Cod sursa(job #275576)
Utilizator | A Andrei AnDrEwBoY | Data | 10 martie 2009 15:59:29 |
---|---|---|---|
Problema | Stramosi | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.57 kb |
#include<stdio.h>
int main()
{
freopen("stramosi.in","r",stdin);
freopen("stramosi.out","w",stdout);
long i,n,m,p,q,stramos; long str[250000];
scanf("%ld %ld",&n,&m);
for(i = 1; i <= n; i++)
scanf("%ld",&str[i]);
for(i = 1; i <= m; i++)
{
scanf("%ld %ld",&q,&p);
stramos = 0;
while(p != 0)
{
if(str[q] == 0) break;
stramos = q = str[q];
p--;
}
printf("%ld\n",stramos);
}
fclose(stdin); fclose(stdout);
return 0;
}