Cod sursa(job #3230636)

Utilizator radu.deaconuDeaconu Radu-Andrei radu.deaconu Data 22 mai 2024 02:36:41
Problema Stramosi Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.43 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream f("stramosi.in");
ofstream g("stramosi.out");

int main()
{
    int n,k,p,q;
    vector<int> a;
    f>>n>>k;
    a.resize(n+1);
    a[0]=0;
    for (int i=1;i<=n;i++)
    {
        f>>a[i];
    }
    for(int i=1;i<=k;i++)
    {
        f>>p>>q;
        for(int j=1;j<=q;j++)
            p=a[p];
        g<<p<<"\n";
    }


    return 0;
}