Cod sursa(job #1778838)
| Utilizator | Data | 14 octombrie 2016 11:24:33 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
const int maxn=20000;
int stramosi[maxn][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';}
}
