Cod sursa(job #447018)
| Utilizator | Data | 27 aprilie 2010 13:42:49 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.46 kb |
#include <cstdio>
int stramos[250001],n,m;
int main()
{
FILE *f=fopen("stramosi.in","r");
FILE *g=fopen("stramosi.out","w");
int i,p,q,j,curent;
fscanf(f,"%d %d",&n,&m);
for(i=1; i<=n; i++)
fscanf(f,"%d",&stramos[i]);
for(i=0; i<m; i++) {
fscanf(f,"%d %d",&q,&p);
curent=stramos[q];
for(j=1; j<p; j++) {
if(!curent) break;
curent=stramos[curent];
}
fprintf(g,"%d\n",curent);
}
fclose(f);
fclose(g);
return 0;
}
