Cod sursa(job #291468)

Utilizator SprzlAbcdefg Sprzl Data 29 martie 2009 21:23:45
Problema Paduri de multimi disjuncte Scor 10
Compilator fpc Status done
Runda Arhiva educationala Marime 0.73 kb
program suma;
const fin = 'disjoint.in';
      fout = 'disjoint.out';
type lp = ^articol;
     articol = ^lp;
var m:array [1..100000] of lp;
    n,x,y,op,i:longint;

procedure join(x,y:integer);
begin
  m[y]^:=m[x]^;
  m[y]:=m[y]^^;

end;

procedure query(x,y:integer);
begin
  if m[x]^ = m[y]^ then
    writeln('DA')
  else
    writeln('NU');
end;

begin
  assign(input,fin);
  assign(output,fout);
  reset(input);
  rewrite(output);
  read(n);
  for i:=1 to n do
  begin
    new(m[i]);
    new(m[i]^);
    m[i]^^:=m[i];
  end;
  readln(x);
  while not eof() do
  begin
    readln(op,x,y);
    if op = 1 then
      join(x,y)
    else
      query(x,y);
  end;

  close(input);
  close(output);
end.