Cod sursa(job #30943)

Utilizator razvi9Jurca Razvan razvi9 Data 15 martie 2007 12:47:56
Problema Stramosi Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.32 kb
#include<stdio.h>
int a[90000],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;}