# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203154 | mayhoubsaleh | Političari (COCI20_politicari) | C++14 | 25 ms | 3704 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |