Cod sursa(job #11219)
Utilizator | Maria Stanciu sigrid | Data | 30 ianuarie 2007 21:34:36 |
---|---|---|---|
Problema | Stramosi | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.42 kb |
//#pragma option -3 -a -Z -O2 -r
#include<fstream.h>
unsigned (*v)=new unsigned[250000];
unsigned long n,m,x,y;
int main()
{unsigned long i;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
f>>n>>m;
v[0]=0;
for(i=1;i<=n;i++) f>>v[i];
for(i=1;i<=m;i++)
{f>>x>>y;
x=v[x];
y--;
while((y)&&(x))
{x=v[x];
y--;
// x=s;
}
g<<x<<'\n';
}
f.close();
g.close();
return 0;
}