Pagini recente » Cod sursa (job #3244058) | Cod sursa (job #1511860) | Cod sursa (job #626992) | Cod sursa (job #2452917) | Cod sursa (job #929330)
Cod sursa(job #929330)
var f,g:text;
i,m,n,c1,c2,q,x,y:longint;
p:array[-1..100010] of longint;
begin
assign(f,'disjoint.in');
assign(g,'disjoint.out');
reset(f);
rewrite(g);
readln(f,n,m);
for i:=1 to m do begin
readln(f,q,x,y);
if q=1 then begin
c1:=x;
while p[c1]<>0 do c1:=p[c1];
c2:=y;
while p[c2]<>0 do c2:=p[c2];
p[c2]:=c1;
end
else begin
c1:=x;
while p[c1]<>0 do c1:=p[c1];
c2:=y;
while p[c2]<>0 do c2:=p[c2];
if c1=c2 then writeln(g,'DA') else writeln(g,'NU');
end;
end;
close(g);
end.