Pagini recente » Cod sursa (job #3244923) | Cod sursa (job #3185132) | Cod sursa (job #3194455) | Cod sursa (job #1266254) | Cod sursa (job #305187)
Cod sursa(job #305187)
var r:array [1..100000] of longint;
i,n,m,c,p,q:longint;
function f(x:longint):longint;
begin
if x = r[x] then f:=x else
begin
r[x]:=f(r[x]);
f:=r[x];
end;
end;
begin
assign(input,'disjoint.in');
reset(input);
assign(output,'disjoint.out');
rewrite(output);
readln(n,m);
for i:=1 to n do
r[i]:=i;
for i:=1 to m do
begin
readln(c,p,q);
if c = 1 then r[f(p)]:=f(q)
else if f(p) = f(q) then
writeln('DA') else writeln('NU');
end;
close(input);
close(output);
end.