Pagini recente » Cod sursa (job #1766245) | Cod sursa (job #2418815) | Cod sursa (job #1963299) | Cod sursa (job #2351700) | Cod sursa (job #929337)
Cod sursa(job #929337)
var f,g:text;
i,m,n,c1,c2,q,x,y:longint;
p:array[-1..100010] of longint;
bufin,bufout:array [1..65000] of byte;
begin
assign(f,'disjoint.in');
assign(g,'disjoint.out');
reset(f);
rewrite(g);
settextbuf(f,bufin);
settextbuf(f,bufout);
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.