Cod sursa(job #30949)

Utilizator razvi9Jurca Razvan razvi9 Data 15 martie 2007 12:50:52
Problema Stramosi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.3 kb
#include<stdio.h>
int a[250001],n,m,q,p;
int main()
{freopen("stramosi.in","r",stdin);
 freopen("stramosi.out","w",stdout);
 scanf("%d %d",&n,&m);
 for(;n;n--)
  scanf("%d",&a[i]);
 for(;m;m--)
 {scanf("%d %d",&q,&p);
  for(;p&&q;p--,q=a[q]);
  printf("%d\n",q);}
 fclose(stdout);
 return 0;}