Cod sursa(job #30944)
Utilizator | Data | 15 martie 2007 12:48:18 | |
---|---|---|---|
Problema | Stramosi | Scor | 80 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.32 kb |
#include<stdio.h>
int a[250000],i,n,m,q,p;
int main()
{freopen("stramosi.in","r",stdin);
freopen("stramosi.out","w",stdout);
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(;m;m--)
{scanf("%d %d",&q,&p);
for(i=2;i<=p&&a[q];i++,q=a[q]);
printf("%d\n",a[q]);}
fclose(stdout);
return 0;}