Pagini recente » Cod sursa (job #3170658) | Cod sursa (job #467737) | Cod sursa (job #281986) | Cod sursa (job #2162524) | Cod sursa (job #1374487)
program multimis;
var t,rg:array[1..100000] of longint;
tip,n,m,x,y,rx,ry,i:longint;
function radacina(nod:longint):longint;
begin
if t[nod]=0 then
radacina:=nod
else
begin
t[nod]:=radacina(t[nod]);
radacina:=t[nod];
end;
end;
begin
assign(input,'disjoint.in'); reset(input);
assign(output,'disjoint.out'); rewrite(output);
readln(n,m);
for i:=1 to m do
begin
readln(tip,x,y);
rx:=radacina(x);
ry:=radacina(y);
case tip of
1: begin
if rg[ry]>rg[rx] then
t[rx]:=ry
else
t[ry]:=rx;
if rg[rx]=rg[ry] then
inc(rg[ry]);
end;
2: begin
if rx=ry then
writeln('DA') else
writeln('NU');
end;
end;
end;
close(input); close(output);
end.