Cod sursa(job #1438037)
Utilizator | Data | 18 mai 2015 22:38:06 | |
---|---|---|---|
Problema | Stramosi | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.66 kb |
#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;
}
}