Pagini recente » Cod sursa (job #296025) | Cod sursa (job #1032157) | Cod sursa (job #2987766) | Cod sursa (job #1641625) | Cod sursa (job #883325)
Cod sursa(job #883325)
program dsf;
var f,g:text;
x,y,z,m,n,i,e1,e2:longint;
t,r:array[1..100001] of longint;
bufin,bufout:array[1..65000] of byte;
function tata(x:longint):longint;
begin
while t[x]<>x do
x:=t[x];
tata:=x;
end;
procedure uneste(x,y:longint);
begin
if (r[x]>r[y]) then t[y]:=x
else t[x]:=y;
if r[x]=r[y] then r[y]:=r[y]+1;
end;
begin
assign(f,'disjoint.in'); reset(f);
assign(g,'disjoint.out'); rewrite(g);
settextbuf(f,bufin);
settextbuf(g,bufout);
readln(f,n,m);
for i:=1 to n do
begin
t[i]:=i;
r[i]:=1;
end;
for i:=1 to m do
begin
readln(f,x,y,z);
e1:=tata(y); e2:=tata(z);
if x=1 then
uneste(e1,e2)
else if (e1=e2) then
writeln(g,'DA')
else
writeln(g,'NU');
end;
close(f);
close(g);
end.