Pagini recente » Cod sursa (job #46437) | Cod sursa (job #1846126) | Cod sursa (job #3173768) | Cod sursa (job #3277726) | Cod sursa (job #244253)
Cod sursa(job #244253)
type lista=^element;
element=record
i:longint;
a:lista;
end;
var v,u:array[1..100000] of lista;
n,m,i,c,x,y:longint;
p:lista;
procedure reuniune(x,y:longint);
begin
u[x]^.a:=v[y];
v[y]:=v[x];
end;
procedure determinare(x,y:longint);
var ok:boolean;
p:lista;
begin
ok:=false;
p:=v[x];
while (p^.a<>nil)and(not ok) do
begin
if p^.i=y then ok:=true;
p:=p^.a;
end; if p^.i=y then ok:=true;
if ok 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
begin
new(p);
p^.i:=i;
p^.a:=nil;
v[i]:=p;
u[i]:=p;
end;
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.