Pagini recente » Cod sursa (job #3141380) | Cod sursa (job #1298209) | Cod sursa (job #2059101) | Cod sursa (job #1933306) | Cod sursa (job #154112)
Cod sursa(job #154112)
var a,b:array[1..250500] of longint;
i,j,n,m,x,y,s:longint;
f,g:text;
begin
assign(f,'stramosi.in');reset(f);
assign(g,'stramosi.out');rewrite(g);
readln(f,n,m);
for i:=1 to n do read(f,a[i]);
for j:=1 to n do begin
s:=j;
for i:=1 to 10 do
if s=0 then break
else s:=a[s];
b[j]:=s;
end;
for j:=1 to m do begin
readln(f,x,y);
s:=x;
while y<>0 do
if s=0 then break
else
if y>=10 then begin
s:=b[s];
y:=y-10;
end
else begin
s:=a[s];
dec(y);
end;
writeln(g,s);
end;
close(f);
close(g);
end.