Pagini recente » Cod sursa (job #3183454) | Cod sursa (job #2711408) | Cod sursa (job #2599375) | Cod sursa (job #2882933) | Cod sursa (job #903202)
Cod sursa(job #903202)
program sdsd;
var f,g:text;
n,m,x,y,i,z,e1,e2:longint;
r,t:array[1..100000] of integer;
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);
readln(f,n,m);
for i:=1 to n do
begin
r[i]:=1;
t[i]:=i;
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
begin
if e1=e2 then
writeln(g,'DA')
else
writeln(g,'NU');
end;
end;
close(f);
close(g);
end.