Pagini recente » Cod sursa (job #1767456) | Cod sursa (job #28072) | Cod sursa (job #1427190) | Cod sursa (job #2969928) | Cod sursa (job #371485)
Cod sursa(job #371485)
var tata:array[1..100000]of longint;
n,m,i,f,x,y:longint;
function find(x:longint):longint;
var aux,r:longint;
begin
r:=x;
while tata[r]<>r do r:=tata[r];
while x<>tata[x] do begin
aux:=x;
x:=tata[x];
tata[aux]:=r;
end;
find:=r;
end;
begin
assign(input,'disjoint.in');reset(input);
assign(output,'disjoint.out');rewrite(output);
read(n,m);
for i:=1 to n do tata[i]:=i;
for i:=1 to m do begin
read(f,x,y);
if f=1 then tata[find(y)]:=find(x)
else begin
if find(x)=find(y) then writeln('DA')
else writeln('NU');
end;
end;
close(output);
end.