Pagini recente » Cod sursa (job #1611353) | Cod sursa (job #2089596) | Cod sursa (job #1001720) | Cod sursa (job #3130375) | Cod sursa (job #15060)
Cod sursa(job #15060)
#include<fstream.h>
unsigned long v[250000],s,c;
unsigned long strm(unsigned long x,unsigned long n,unsigned long c)
{if(c<=n)
{s=v[x];
x=s;
strm(x,n,c+1);
}
else return s;
}
int main()
{int i,n,m,x;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
f>>n>>m;
for(i=1;i<=n;i++) f>>v[i];
for(i=1;i<=m;i++)
{f>>x>>n;
g<<strm(x,n,1)<<'\n';
}
f.close();
g.close();
return 0;
}