Cod sursa(job #228318)

Utilizator radu_voroneanuVoroneanu Radu Stefan radu_voroneanu Data 6 decembrie 2008 22:51:18
Problema Paduri de multimi disjuncte Scor 10
Compilator fpc Status done
Runda Arhiva educationala Marime 0.52 kb
type point=^longint;

var a:array[1..100000] of point;
    f,g:text;
    tip,x,y,m,n,i:longint;

begin
 assign(f,'disjoint.in'); reset(f);
 assign(g,'disjoint.out'); rewrite(g);
 read(f,n);
 for i:=1 to n do begin
  new(a[i]);
  a[i]^:=i;
 end;
 read(f,m);
 for i:=1 to m do begin
  read(f,tip);
  if tip=1 then begin
   read(f,x,y);
   a[x]:=a[y];
  end;
  if tip=2 then begin
   read(f,x,y);
   if a[x]^=a[y]^ then
    writeln(g,'DA')
   else
    writeln(g,'NU');
  end;
 end;
 close(f); close(g);
end.