Pagini recente » Cod sursa (job #844361) | Cod sursa (job #2033491) | Cod sursa (job #1193970) | Cod sursa (job #308779) | Cod sursa (job #244268)
Cod sursa(job #244268)
var v:array[1..100000] of longint;
n,m,i,c,x,y:longint;
procedure reuniune(x,y:longint); inline;
var w,j:longint;
begin
w:=v[y];
for j:=1 to n do if v[j]=w then v[j]:=v[x];
end;
procedure determinare(x,y:longint);inline;
begin
if v[x]=v[y] then writeln('DA')
else writeln('NU');
end;
begin
assign(input,'disjoint.in'); reset(input);
assign(output,'disjoint.out'); rewrite(output);
readln(n,m);
for i:=1 to n do v[i]:=i;
for i:=1 to m do
begin
readln(c,x,y);
if c=1 then reuniune(x,y)
else determinare(x,y);
end;
close(output);
close(input);
end.