Pagini recente » Cod sursa (job #637687) | Cod sursa (job #2120471) | Cod sursa (job #2501610) | Cod sursa (job #1978304) | Cod sursa (job #1399330)
program disjoint;
type
tabel=array[0..100001] of longword;
buf=array[0..1 shl 17] of char;
var
t:tabel; ff1,ff2:buf;
n,m,i,j,x,y,tip:longword;
f1,f2:text;
function findroot(x:longword):longword;
begin
while t[x]>0 do x:=t[x];
findroot:=x;
end;
begin
assign (f1,'disjoint.in');
assign (f2,'disjoint.out');
reset (f1);
rewrite (f2);
settextbuf(f1,ff1);
settextbuf(f2,ff2);
readln (f1,n,m);
for i:=1 to m do begin
readln (f1,tip,x,y);
x:=findroot(x);
y:=findroot(y);
if tip=1 then t[x]:=y else
if x=y then writeln (f2,'DA') else writeln (f2,'NU');
end;
close (f1);
close (f2);
end.