Pagini recente » Cod sursa (job #752911) | Cod sursa (job #3206210) | Cod sursa (job #2774155) | Cod sursa (job #3183802) | Cod sursa (job #3276806)
#include <fstream>
#include<vector>
using namespace std;
ifstream cin("stramosi.in");
ofstream cout("stramosi.out");
int n,m;
vector<int>t;
int ver(int nod, int cat, int cnt=0){
while(cnt!=cat)
{
cnt++;
nod=t[nod];
}
return nod;
}
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(0);cout.tie(0);
cin>>n>>m;
t.resize(n+1);
for(int i=1; i<=n; ++i)
cin>>t[i];
int q,p;
for(int i=1; i<=m; ++i){
cin>>q>>p;
cout<<ver(q,p)<<'\n';
}
return 0;
}