Pagini recente » Cod sursa (job #457603) | Cod sursa (job #2804801) | Cod sursa (job #1641262) | Cod sursa (job #1466298) | Cod sursa (job #307690)
Cod sursa(job #307690)
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) = r[f(q)] then
writeln('DA') else writeln('NU');
end;
close(input);close(output);
end.