Pagini recente » Cod sursa (job #1642394) | Cod sursa (job #1139815) | Cod sursa (job #96606) | Cod sursa (job #2166919) | Cod sursa (job #892687)
Cod sursa(job #892687)
program info;
var t,h:array[0..100010] of longint;
n,m:longint;
f,g:text;
function tata(x:longint):longint;
BEGIN
if x=t[x] then
tata:=x
else
BEGIN
t[x]:=tata(t[x]);
tata:=t[x];
END;
END;
procedure citire;
var i,op,x,y:longint;
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;
h[i]:=1;
END;
for i:=1 to m do
BEGIN
readln(f,op,x,y);
if op=1 then
BEGIN
if tata(x)<>tata(y) then
begin
if h[x]>h[y] then
t[y]:=x
else
t[x]:=y;
if h[x]=h[y] then
h[y]:=h[y]+1;
end;
END
else
BEGIN
if tata(x)=tata(y) then
writeln(g,'DA')
else
writeln(g,'NU');
END;
END;
END;
BEGIN
citire;
close(f);
close(g);
END.