Submission #203154

#TimeUsernameProblemLanguageResultExecution timeMemory
203154mayhoubsalehPolitičari (COCI20_politicari)C++14
70 / 70
25 ms3704 KiB
#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 timeMemoryGrader output
Fetching results...