Cod sursa(job #1622473)

Utilizator robertadRoxana Rodile robertad Data 1 martie 2016 11:46:19
Problema Paduri de multimi disjuncte Scor 10
Compilator fpc Status done
Runda Arhiva educationala Marime 0.79 kb
program mire;
var f,g:text;
     bufin,bufout:array[1.. 1 shl 16] of byte;
     n,m,c,x,y,i:longint;
    t:array[1..100000] of longint;
function rad(nod:longint):longint;
begin
 if t[nod]<0  then
  rad:=nod
 else
    begin
        t[nod]:=rad(t[nod]);
        rad:=t[nod];
    end
end;
begin
assign(f,'disjoint.in'); reset(f);
assign(g,'disjoint.out'); rewrite(g);
settextbuf(f,bufin); settextbuf(g,bufout);
  readln(f,n,m);
  for i:=1 to n do
    t[i]:=-1;
  for i:=1 to m do
    begin
       readln(f,c,x,y);
       if c=1 then
          begin
             t[y]:=x;
          end
       else
         begin
            if rad(x)=rad(y) then
               writeln(g,'DA')
             ELSE
                writeln(g,'NU')
         end;

    end;
close(f);
close(g);
end.