Pagini recente » Monitorul de evaluare | Cod sursa (job #2702266) | Cod sursa (job #1943954) | Cod sursa (job #2616839) | Cod sursa (job #3310636)
#include <fstream>
using namespace std;
ifstream in("stramosi.in");
ofstream out("stramosi.out");
const int nmax = 250000, lgmax = 18;
int n, nrq, node, topp, father[nmax + 2];
int main(){
in>>n>>nrq;
for(int i = 1; i <= n; i++){
in>>father[i];
}
for(int i = 1; i <= nrq; i++){
in>>node>>topp;
for(int it = 1; it <= topp; it++)
node = father[node];
out<<node<<"\n";
}
return 0;
}