Pagini recente » Cod sursa (job #1654212) | Cod sursa (job #1212595) | Cod sursa (job #2392833) | Cod sursa (job #910658) | Cod sursa (job #2586900)
// Stramosi.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("stramosi.in");
ofstream fout("stramosi.out");
int d[250000], N, M, Q, P;
void rasp(int Q, int P) {
int T = d[Q], R;
while (P > 0) {
R = T;
T = d[R];
P--;
}
fout << R << endl;
}
int main()
{
fin >> N >> M;
for (int i = 1; i <= N; i++)
fin >> d[i];
for (int j = 1; j <= M; j++) {
fin >> Q >> P;
rasp(Q, P);
}
cout << d[12];
return 0;
}