Cod sursa(job #382107)
Utilizator | Balu Cristian cristi12345 | Data | 12 ianuarie 2010 21:07:31 |
---|---|---|---|
Problema | Stramosi | Scor | 80 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 0.47 kb |
program stramosi;
var a:array[1..260000]of longint;
i,j,n,m,x,y,stramos:longint;
fin,fout:text;
begin
assign(fin,'stramosi.in'); reset(fin);
assign(fout,'stramosi.out'); rewrite(fout);
readln(fin,n,m);
for i:=1 to n do read(fin,a[i]);
for j:=1 to m do begin
readln(fin,x,y);
stramos:=x;
for i:=1 to y do
if stramos = 0 then break
else stramos:=a[stramos];
writeln(fout,stramos);
end;
close(fin); close(fout);
end.