Pagini recente » Cod sursa (job #332326) | Cod sursa (job #1070894) | Cod sursa (job #1475650) | Cod sursa (job #962449) | Cod sursa (job #343747)
Cod sursa(job #343747)
var t:array[1..100000] of longint;
n,m,i,cod,x,y,s1,s2,aux:longint;
f,g:text;
function s(el:longint):longint;
begin
if t[el]=el then
s:=el
else
s:=s(t[el]);
end;
procedure unire(a,b:longint);
begin
t[a]:=b;
end;
begin
assign(f,'disjoint.in');
assign(g,'disjoint.out');
reset(f);rewrite(g);
readln(f,n,m);
for i:=1 to n do
t[i]:=i;
for i:=1 to m do
begin
readln(f,cod,x,y);
if cod=1 then
unire(s(x),s(y))
else
if s(x)=s(y) then
writeln(g,'DA')
else
writeln(g,'NU');
end;
close(f);close(g);
end.