Pagini recente » Cod sursa (job #3167554) | Cod sursa (job #643960) | Cod sursa (job #520588) | Cod sursa (job #1439222) | Cod sursa (job #899884)
Cod sursa(job #899884)
#include <iostream>
#include <fstream>
using namespace std;
int m,n,k=0,v[100];
int stramos(int q)
{
if(k>0)
{
q=v[q];
k--;
stramos(q);
}
else if(k==0)
return q;
}
void citire()
{
int p,q;
ifstream in("date.in");
in>>n>>m;
for(int i=1; i<=n; i++)
in>>v[i];
for(int i=1; i<=n; i++)
cout<<v[i]<<" ";
for(int i=1; i<=m; i++)
{
in>>q>>p;
k=p;
cout<<stramos(q)<<endl;
}
}
int main()
{
citire();
return 0;
}