Cod sursa(job #2754601)
| Utilizator | Data | 26 mai 2021 04:08:33 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <fstream>
#define fs "stramosi"
using namespace std;
ifstream f(fs".in");
ofstream g(fs".out");
int a[250001];
int main() {
int n,m,x,y,aux;
f>>n>>m;
bool ok = true;
for(int i = 1 ; i <= n ; ++i )
{f>>a[i];
if(a[i]!=i-1)
ok=false;
}
if(ok){
while(f>>x>>y)
g<<max(x-y,0)<<" ";
}
else
for(int i = 0 ; i < m ; ++i )
{ f>>x>>y;
aux=x;
while(aux>0 && y>0)
{
aux=a[aux];
y--;
}
g<<aux<<" ";}
return 0;
}
