Cod sursa(job #52365)
Utilizator | Data | 18 aprilie 2007 19:20:08 | |
---|---|---|---|
Problema | Stramosi | Scor | 80 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.42 kb |
#include<fstream.h>
#define dim 250001
ifstream fin("stramosi.in");
ofstream fout("stramosi.out");
int n,m,i,a[dim],p,q,st;
int main()
{
fin>>n>>m;
for(i=1;i<=n;i++)
{
fin>>a[i];
}
for(i=1;i<=m;i++)
{
fin>>q>>p;
st=a[q];
while(p>1)
{
st=a[st];
if(!st)
break;
p--;
}
fout<<st<<'\n';
}
return 0;
}