Cod sursa(job #2543912)
Utilizator | Gherghinescu Mihai Andrei XXMihaiXX969 | Data | 11 februarie 2020 17:16:18 |
---|---|---|---|
Problema | Stramosi | Scor | 70 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("stramosi.in");
ofstream out("stramosi.out");
const int DIM = 250000;
int p[DIM];
int parinte(int cnt,int x,int y)
{
if(cnt == y)
return x;
if(x == 0)
return 0;
return parinte(cnt + 1,p[x], y);
}
int main()
{
int n, m;
in >> n >> m;
for(int i = 1; i <= n; i++)
in >> p[i];
while(m--)
{
int x, y;
in >> x >> y;
out << parinte(0,x,y)<<'\n';
}
return 0;
}