Cod sursa(job #1417223)

Utilizator laura.calimanLaura Caliman laura.caliman Data 9 aprilie 2015 22:12:22
Problema Paduri de multimi disjuncte Scor 40
Compilator fpc Status done
Runda Arhiva educationala Marime 0.48 kb
var n,m,i,j,k,x,y,t:longint;
    a:array[1..100000] of longint;
    
begin
  assign(input,'disjoint.in');
  assign(output,'disjoint.out');
  reset(input);
  rewrite(output);
  read(n,m);
  for i:=1 to n do a[i]:=i;
  for i:=1 to m do begin
    read(k,x,y);
    if k=2 then begin 
      if a[x]=a[y] then writeln('DA')
        else writeln('NU');
    end;
    if k=1 then begin
      t:=a[y];
      for j:=1 to n do
        if a[j]=t then a[j]:=a[x];
    end;
  end;
end.