Pagini recente » Cod sursa (job #421108) | Cod sursa (job #2438299) | Cod sursa (job #2806240) | Cod sursa (job #276305) | Cod sursa (job #885636)
Cod sursa(job #885636)
program multimi;
var f,g:text;
x,y,z,m,n,i,x1,x2:longint;
t,r:array[1..100001] of longint;
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;
function arb(x:longint):longint;
begin
if x=t[x] then
arb:=x else
begin
arb:=arb(t[x]);
t[x]:=t[t[x]];
end;
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);
x1:=arb(y); x2:=arb(z);
if x=1 then
uneste(x1,x2) else if x1=x2 then
writeln(g,'DA') else
writeln(g,'NU');
end;
close(f); close(g);
end.