Pagini recente » Cod sursa (job #1137081) | Cod sursa (job #212133) | Cod sursa (job #2760170) | Cod sursa (job #635884) | Cod sursa (job #1622582)
program mire;
var f,g:text;
bufin,bufout:array[1.. 1 shl 16] of byte;
n,m,c,x,y,i,z,r:longint;
t:array[1..100000] of longint;
function ra(nod:longint):longint;
begin
if t[nod]<>0 then
ra:=ra(t[nod])
else
ra:=nod;
end;
function rad(nod:longint):longint;
begin
while t[nod]<>0 do
nod:=t[nod];
rad:=nod;
end;
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 m do
begin
readln(f,c,x,y);
if c=1 then
begin
r:=rad(x);
z:=rad(y);
t[z]:=r;
end
else
begin
if rad(x)=rad(y) then
writeln(g,'DA')
ELSE
writeln(g,'NU')
end;
end;
//for i:=1 to n do
//write(g,t[i],' ');
close(f);
close(g);
end.