Mai intai trebuie sa te autentifici.
Cod sursa(job #3240546)
| Utilizator | Data | 16 august 2024 13:30:33 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("stramosi.in");
ofstream fout("stramosi.out");
const int NMAX = 250000;
int stramosulLui[NMAX+1];
int N, M;
int P, Q;
void stramos(int x, int y)
{
int ans = x;
int cnt = y;
while(cnt--)
{
ans = stramosulLui[ans];
}
fout << ans << '\n';
}
int main()
{
fin >> N >> M;
for(int i=1; i<=N; i++)
fin >> stramosulLui[i];
while(M--)
{
fin >> Q >> P;
stramos(Q,P);
}
return 0;
}
