Cod sursa(job #504443)
| Utilizator | Data | 27 noiembrie 2010 18:28:58 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.52 kb |
#include <stdio.h>
using namespace std;
#define nmax 250005
int tata[nmax];
int n, t;
void citire ()
{
int i;
freopen("stramosi.in","r",stdin);
scanf("%d %d ", &n, &t);
for (i = 1; i <= n; ++i)
scanf("%d ", &tata[i]);
}
void solve ()
{
int i, q, p;
freopen("stramosi.out","w",stdout);
for (i = 1; i <= t; ++i)
{
scanf("%d %d ", &q, &p);
while ( tata[q] && p>1 )
{
q = tata[q];
p --;
}
printf("%d\n", tata[q]);
}
}
int main ()
{
citire ();
solve ();
return 0;
}
