Cod sursa(job #2371098)
Utilizator | Tache Radu Ioan JohnnyT | Data | 6 martie 2019 15:45:58 |
---|---|---|---|
Problema | Stramosi | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <cmath>
#include <vector>
#include <fstream>
#include <iostream>
using namespace std;
int main(){
int n, m, p, q;
fstream f("stramosi.in", fstream::in), g("stramosi.out", fstream::out);
f >> n >> m;
vector<int> stramosi(n + 1);
for(int i = 1; i <= n; i++){
f >> stramosi[i];
}
for(int z = 0; z < m; z++){
f >> q >> p;
while(p){
q = stramosi[q];
p--;
if(q == 0){
break;
}
}
g << q << endl;
}
}