Cod sursa(job #2279978)

Utilizator hongnhoNGUYENHONGNHO hongnho Data 10 noiembrie 2018 10:46:46
Problema Stramosi Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
//--------DO NOTHING---------
#include <bits/stdc++.h>
#include <bitset>
//#define x first
//#define y second
#define mn 250005
#define pb push_back
#define oo 1000000007
//#define int long long
#define DoNothing "stramosi"
#define PI 3.1415926535897
#define ii pair< int, int>
#define memset(f, a) memset(f, a, sizeof(f))
#define forr(i, a, b) for(int i= a; i<= b; i++)


using namespace std;

int n, t, p[mn][25];

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    freopen(DoNothing".inp", "r", stdin);
    freopen(DoNothing".out", "w", stdout);

    cin>> n>> t;
    forr(i, 1, n) cin>> p[i][0];

    forr(i, 1, 23)
    forr(j, 1, n)
    p[j][i]= p[p[j][i- 1]][i- 1];

    while(t--)
    {
        int u, v;
        cin>> u>> v;
        forr(i, 0, 23)
        if((v>> i)& 1) u= p[u][i];
        cout<< u<< "\n";
    }

    return 0;
}