Cod sursa(job #3231608)

Utilizator alexionut05Alexandru-Ionut Tincu alexionut05 Data 27 mai 2024 12:22:58
Problema Stramosi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.25 kb
#include<fstream>
int n,m,v[1<<18],i,x,y,k;std::fstream f("stramosi.in");std::ofstream g("stramosi.out");main(){for(f>>n>>m;i<n;f>>v[++i],k+=(v[i]==i-1));if(k==n)while(f>>x>>y)g<<(x>=y?x-y:0)<<'\n';else while(f>>x>>y){for(;x&&y--;x=v[x]);g<<x<<'\n';}}