Cod sursa(job #307690)
| Utilizator | Data | 24 aprilie 2009 18:06:20 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 90 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
var r:array [1..100000] of longint;
i,n,m,c,p,q:longint;
function f(x:longint):longint;
begin
if x = r[x] then f:=x else
begin
r[x]:=f(r[x]);
f:=r[x];
end;
end;
begin
assign(input,'disjoint.in');reset(input);assign(output,'disjoint.out');rewrite(output);
readln(n,m);
for i:=1 to n do
r[i]:=i;
for i:=1 to m do
begin
readln(c,p,q);
if c = 1 then r[f(p)]:=f(q)
else if f(p) = r[f(q)] then
writeln('DA') else writeln('NU');
end;
close(input);close(output);
end.
