Pagini recente » Cod sursa (job #1702589) | Cod sursa (job #1372053) | Cod sursa (job #3133653) | Cod sursa (job #2728181) | Cod sursa (job #892719)
Cod sursa(job #892719)
program info;
var t,h:array[0..100010] of longint;
bufin,bufout:array[1..65000] of byte;
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,x1,y1:longint;
BEGIN
assign(f,'disjoint.in'); reset(f);
assign(g,'disjoint.out'); rewrite(g);
settextbuf(f,bufin);
settextbuf(g,bufout);
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);
x1:=tata(x);
y1:=tata(y);
if op=1 then
BEGIN
if x1<>y1 then
begin
if h[x1]>h[y1] then
t[y1]:=x1
else
t[x1]:=y1;
if h[x1]=h[y1] then
h[y1]:=h[y1]+1;
end;
END
else
BEGIN
if x1=y1 then
writeln(g,'DA')
else
writeln(g,'NU');
END;
END;
END;
BEGIN
citire;
close(f);
close(g);
END.