Pagini recente » Cod sursa (job #1029482) | Cod sursa (job #1021719) | template/moisil-2015 | Istoria paginii template/fmi-no-stress-4/footer | Cod sursa (job #885700)
Cod sursa(job #885700)
program multimi;
var f,g:text;
x,y,z,m,n,i,x1,x2:longint;
t,r:array[1..100001] of longint;
function arb(x:longint):longint;
begin
if x=t[x] then
arb:=x else
begin
t[x]:=arb(t[x]);
arb:=t[x];
end;
end;
procedure uneste(x,y:longint);
begin
if (r[x]>r[y]) then begin
t[y]:=arb(x);
end
else
begin
t[x]:=arb(y);
end;
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
t[i]:=i;
r[i]:=1;
end;
for i:=1 to m do
begin
readln(f,x,y,z);
if x=1 then begin
uneste(y,z);
end else if t[y]=t[z] then
writeln(g,'DA') else
writeln(g,'NU');
end;
close(f); close(g);
end.