Cod sursa(job #2246296)
Utilizator | Data | 26 septembrie 2018 21:49:33 | |
---|---|---|---|
Problema | Stramosi | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
int N,M,x,y;
vector<int>D[250001];
int main()
{ f>>N>>M;
for(int i=1;i<=N;i++)
{
f>>x;
if(x!=0)
{
D[i].push_back(x);
for(int j=0;j<D[x].size();j++)
D[i].push_back(D[x][j]);
}
}
for(int i=1;i<=M;i++)
{
f>>x>>y;
int m=D[x].size();
if(y>m)
g<<0<<"\n";
else
g<<D[x][y-1]<<"\n";
}
return 0;
}