Pagini recente » Cod sursa (job #137531) | Cod sursa (job #1182078) | Cod sursa (job #3281456) | Cod sursa (job #1790857) | Cod sursa (job #882371)
Cod sursa(job #882371)
program dsf;
var f,g:text;
x,y,z,m,n,i:longint;
t,r:array[1..100001] of longint;
function tata(x:longint):longint;
begin
if t[x]<>x then
tata:=tata(t[x])
else
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);
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);
if x=1 then
uneste(tata(y),tata(z))
else if (tata(y)=tata(z)) then
writeln(g,'DA')
else
writeln(g,'NU');
end;
close(f);
close(g);
end.