Cod sursa(job #542361)

Utilizator Wanda92Nenu Anda Roxana Wanda92 Data 26 februarie 2011 12:25:21
Problema Gossips Scor 0
Compilator fpc Status done
Runda Romanian Master in Mathematics and Sciences 2011, Ziua 2 Marime 0.95 kb
program info;
type nod=record
     nr:integer;
     barfa:set of byte;
         end;
     vector=array [1..100000] of nod;
var f,g:text; i,n,q,m,x,y:longint; j:word;  v:vector;

procedure barfitori(n,x,y:longint; var v:vector); var p,t:longint;
begin p:=y;
while p<>0 do begin
      for t:=1 to n do if v[t].nr=x then v[t].barfa:=v[t].barfa+[p];
      t:=x;
      repeat v[t].barfa:=v[t].barfa+[p];
             t:=v[t].nr;
      until t=0;
      p:=v[p].nr;
      end;
end;

begin
assign(f,'gossips.in'); reset(f);
assign(g,'gossips.out'); rewrite(g);
readln(f,n,m,q);
for i:=1 to n do begin v[i].nr:=0; v[i].barfa:=[]; end;
for i:=1 to m do begin readln(f,x,y); v[y].nr:=x; end;
for i:=1 to q do begin readln(f,j,x,y);
    if j=1 then begin if (y in v[x].barfa) then writeln(g,'YES')
                                           else writeln(g,'NO');
                end
    else barfitori(n,x,y,v);
    end;
close(f); close(g);
end.