Pagini recente » Cod sursa (job #1492685) | Cod sursa (job #864839) | Cod sursa (job #789924) | Rating Nechita Roberta Florina (NechitaRoberta) | Cod sursa (job #1438037)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
using namespace std;
int n,m,i,q,p,x,j,k,l;
vector <int> t[250005];
int main()
{
f>>n;
f>>m;
for(i=1;i<=n;i++)
{
f>>x;
cout<<"OK";
t[i].push_back(i);
t[i].push_back(x);
j=1;
k=i;
while(t[k][t[k].size()-1]!=0)
{
t[k].push_back(t[x][j]);
j++;
}
}
for(i=1;i<=m;i++)
{
f>>q;f>>p;
if(t[q].size()>p)
g<<t[q][p]<<endl;
else
g<<0<<endl;
}
}