Cod sursa(job #1179710)
Utilizator | Mihai Chihai Mihai_Chihai | Data | 29 aprilie 2014 07:46:36 |
---|---|---|---|
Problema | Stramosi | Scor | 70 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 0.55 kb |
var p:array[1..250000] of longint;
n,m,x,y,i,j:longint;
bufin,bufout:array[1..1 shl 17] of char;
begin
assign(input,'stramosi.in');
reset(input);
assign(output,'stramosi.out');
rewrite(output);
settextbuf(input,bufin);
settextbuf(output,bufout);
readln(n,m);
for i:=1 to n do read(p[i]);
for i:=1 to m do begin
readln(x,y);
for j:=1 to y do
begin
x:=p[x];
if x=0 then break;
end;
writeln(x);
end;
close(output);
end.