Cod sursa(job #550871)
| Utilizator | Data | 9 martie 2011 23:36:27 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 40 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
var i,j,n,m,c,x,y,k:longint;
f1,f2:text;
a:array[1..100000]of longint;
begin
assign(f1,'disjoint.in');
reset(f1);
assign(f2,'disjoint.out');
rewrite(f2);
readln(f1,n,m);
for i:=1 to n do
a[i]:=i;
for i:=1 to m do
begin
readln(f1,c,x,y);
if c=1 then
begin
k:=a[y];
for j:=1 to n do
if a[j]=k then a[j]:=a[x];
end
else
begin
if a[x]=a[y] then writeln(f2,'DA') else writeln(f2,'NU');
end;
end;
close(f1);
close(f2);
end.
