Pagini recente » Diferente pentru problema/pastile intre reviziile 2 si 3 | Cod sursa (job #2341330) | Diferente pentru problema/expand intre reviziile 53 si 52 | Monitorul de evaluare | Cod sursa (job #1417260)
var n,m,i,j,k,x,y,t:longint;
a:array[1..100000] of longint;
begin
assign(input,'disjoint.in');
assign(output,'disjoint.out');
reset(input);
rewrite(output);
read(n,m);
for i:=1 to n do a[i]:=i;
for i:=1 to m do begin
read(k,x,y);
if k=2 then begin
j:=x;
t:=y;
while t<>a[t] do
t:=a[t];
while j<>a[j] do
j:=a[j];
if a[j]=a[t] then writeln('DA')
else writeln('NU');
end;
if k=1 then begin
a[y]:=a[x];
end;
end;
end.