Cod sursa(job #1001589)

Utilizator IonMosnoiIon Mosnoi IonMosnoi Data 25 septembrie 2013 17:00:54
Problema Stramosi Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.51 kb
program ideone;
var m,n,i,j:integer;
fis,fo:text;
a,b,c,d:array[1..1000] of integer;
function find(h,b:integer):integer;
begin
for j:=1 to b do begin
if(h<>0) then begin
h := a[h];
end;
end;
find := h;
end;
begin
Assign(fis, 'adunare.in');
  Reset(fis);
read(fis,n);
readln(fis,m);
for i:=1 to n do read(a[i]);
readln(fis);
i:=0;
while not eon(fis) do begin
i:=i+1;
read(fis,b[i]);
readln(fis,c[i]);

end;
Close(fis);
 Assign(fo, 'adunare.out');
  Rewrite(fo);
for i:=1 to m do writeln(fo,find(b[i],c[i]));
Close(fo);

end.