Pagini recente » Cod sursa (job #1369321) | Cod sursa (job #2063048) | Cod sursa (job #222324) | Rating Malancioiu Daniel (DannyDMG) | Cod sursa (job #834664)
Cod sursa(job #834664)
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
string be,ki;
be="stramosi.in";
ki="stramosi.out";
ifstream f;
ofstream g;
f.open(be.c_str());
g.open(ki.c_str());
int n,m,i,a,b,p,db;
vector<int> os;
f >> n >> m;
os.push_back(0);
for(i=1; i<=n; ++i)
{
f >> a;
os.push_back(a);
}
for(i=1; i<=m; ++i)
{
f >> a >> b;
db=0;
p=a;
while( (db!=b) )
{
p=os[a];
a=p;
if(p==0)
{
db=b;
}
else
{
db++;
}
}
g << p << endl;
}
f.close();
g.close();
return 0;
}