Cod sursa(job #1399290)

Utilizator ButnaruButnaru George Butnaru Data 24 martie 2015 17:52:29
Problema Paduri de multimi disjuncte Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.5 kb
program disjoint;
type
tabel=array[0..100001] of longint;
var
t:tabel;
n,m,i,j,x,y,tip:longint;
f1,f2:text;
function findroot(x:longint):longint;
begin
while t[x]>0 do x:=t[x];
findroot:=x;
end;
begin
assign (f1,'disjoint.in');
assign (f2,'disjoint.out');
reset (f1);
rewrite (f2);
readln (f1,n,m);
for i:=1 to m do begin
readln (f1,tip,x,y);
x:=findroot(x);
y:=findroot(y);
if tip=1 then t[x]:=y else
if x=y then writeln (f2,'DA') else writeln (f2,'NU');
end;
close (f1);
close (f2);
end.