Pagini recente » Cod sursa (job #627028) | Cod sursa (job #1311825) | Cod sursa (job #289799) | Cod sursa (job #439131) | Cod sursa (job #293621)
Cod sursa(job #293621)
var x,gr:Array[1..100005] of longint;
op,n,m,i,j,k,a,b,t,cc,tt:longint;
begin
assign(input,'disjoint.in');
reset(input);
assign(output,'disjoint.out');
rewrite(output);
read(n,m);
for i:=1 to n do
begin
x[i]:=i;
gr[i]:=1;
end;
for i:=1 to m do
begin
read(op,a,b);
if op=1 then
begin
t:=a;
while x[t]<>t do t:=x[t];
tt:=a;
while x[tt]<>tt do begin
cc:=x[tt];
x[tt]:=t;
tt:=cc;
end;
t:=b;
while x[t]<>t do t:=x[t];
tt:=b;
while x[tt]<>tt do
begin
cc:=x[tt];
x[tt]:=t;
tt:=cc;
end;
end;
if t<>x[a] then
if gr[a]>gr[b] then
x[b]:=a
else x[a]:=b;
if gr[a]=gr[b] then gr[b]:=gr[b]+1;
end
else
begin
t:=a;
while x[t]<>t do t:=x[t];
tt:=a;
while x[tt]<>tt do begin
cc:=x[tt];
x[tt]:=t;
tt:=cc;
end;
t:=b;
while x[t]<>t do t:=x[t];
if t=x[a] then writeln('DA')
else writeln('NU');
tt:=b;
while x[tt]<>tt do
begin
cc:=x[tt];
x[tt]:=t;
tt:=cc;
end;
end;
end;
close(input);
close(output);
end.