Pagini recente » Cod sursa (job #1341488) | Cod sursa (job #2363547) | Cod sursa (job #1124400) | Cod sursa (job #1718356) | Cod sursa (job #1778433)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
const int maxn=4000;
int stramosi[1000][16000];
int N,M;
int main()
{
int i,j,a,b;
f>>N>>M;
for (i=1;i<=N;i++)
f>>stramosi[1][i];
for (i=2;i<=19;i++)
for (j=1;j<=N;j++)
stramosi[i][j]=stramosi[1][stramosi[i-1][j]];
g<<stramosi[22][1];
for (i=1;i<=M;i++)
{f>>a>>b;
if (a>19) g<<0<<'\n';
else g<<stramosi[b][a]<<'\n';}
}