Pagini recente » Cod sursa (job #2401567) | Cod sursa (job #2973550) | Cod sursa (job #73015) | Cod sursa (job #2405541) | Cod sursa (job #293689)
Cod sursa(job #293689)
var x,gr:Array[1..100010] of longint;
op,n,m,i,j,k,a,b,t,cc,tt:longint;
function caut(var nod:longint):longint;
begin
t:=nod;
while t<>x[t] do t:=x[t];
cc:=t;
t:=nod;
while t<>x[t] do
begin
tt:=x[t];
x[t]:=cc;
t:=tt;
end;
caut:=t;
end;
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
if caut(a)<>caut(b)
then
begin
if gr[x[a]]<gr[x[b]] then
x[x[a]]:=x[b]
else x[x[b]]:=x[a];
if gr[x[a]]=gr[x[b]] then
inc(gr[x[b]]);
end else
else
if caut(a)=caut(b) then writeln('DA')
else writeln('NU');
end;
close(input);
close(output);
end.