Pagini recente » Cod sursa (job #2552965) | Cod sursa (job #2620572) | Cod sursa (job #2504801) | Cod sursa (job #2700810) | Cod sursa (job #244236)
Cod sursa(job #244236)
var v:array[1..100000] of longint;
n,m,i,c,x,y:longint;
procedure reuniune(x,y:longint);
var j,d:longint;
begin
d:=v[y];
for j:=1 to n do if v[j]=d then v[j]:=v[x];
end;
procedure determinare(x,y:longint);
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.