Pagini recente » Cod sursa (job #1357075) | Cod sursa (job #1055841) | Cod sursa (job #1353997) | Cod sursa (job #772580) | Cod sursa (job #1001589)
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.