Cod sursa(job #2754740)
Utilizator | Data | 26 mai 2021 14:14:56 | |
---|---|---|---|
Problema | Stramosi | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.49 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
int n,m,nr,p,q,i,tati[10001],aux;
int main(){
f>>n>>m;
for(i=1;i<=n;i++)
{
f>>tati[i];
}
for(i=1;i<=m;i++)
{
f>>q>>p;
aux=q;
while(p>0 && aux!=0)
{
aux=tati[aux];
p--;
}
if(p>0)
{
g<<0<<'\n';
}
else
g<<aux<<'\n';
}
}