Cod sursa(job #1778221)
| Utilizator | Data | 13 octombrie 2016 17:01:34 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
const int maxn=400000;
int stramosi[21][maxn];
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]];
for (i=1;i<=M;i++)
{f>>a>>b;
g<<stramosi[b][a]<<'\n';}
}
