Cod sursa(job #3276798)
Utilizator | Data | 14 februarie 2025 19:15:48 | |
---|---|---|---|
Problema | Stramosi | Scor | 70 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
const int nMax = 250002;
int tat[nMax], n;
void solve(int nod, int p)
{
int cnt = 0;
while(tat[nod] != 0 && cnt < p)
cnt++,
nod = tat[nod];
if(cnt == p)
g << nod<<'\n';
else
g << 0 << '\n';
}
int main()
{
int m;
f >> n >> m;
for(int i=1; i<=n; i++)
f >> tat[i];
int nod, p;
while(m--)
{
f >> nod >> p;
solve(nod, p);
}
}