Submission #203154

# Submission time Handle Problem Language Result Execution time Memory
203154 2020-02-19T15:07:50 Z mayhoubsaleh Političari (COCI20_politicari) C++14
70 / 70
25 ms 3704 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long

using namespace std;
ll n,k;
ll a[555][555];
vector<ll>v;
ll pos[555][555];
ll th;
void go(ll x,ll last){
    if(pos[x][last]){
        th=pos[x][last];
        return;
    }
    pos[x][last]=v.size();
    v.pb(x);
    go(a[x][last],x);
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>k;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            cin>>a[i][j];
        }
    }

    v.pb(1);
    go(2,1);
    k--;
    if(k<th){
        cout<<v[k]<<endl;
        return 0;
    }
    k-=th;
    k=k%(v.size()-th);
    cout<<v[k+th]<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 9 ms 2168 KB Output is correct
3 Correct 16 ms 2936 KB Output is correct
4 Correct 19 ms 3192 KB Output is correct
5 Correct 25 ms 3448 KB Output is correct
6 Correct 24 ms 3192 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 7 ms 1272 KB Output is correct
9 Correct 9 ms 2296 KB Output is correct
10 Correct 22 ms 3064 KB Output is correct
11 Correct 24 ms 3704 KB Output is correct
12 Correct 23 ms 3704 KB Output is correct
13 Correct 5 ms 760 KB Output is correct
14 Correct 7 ms 1400 KB Output is correct