# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
732250 | vjudge1 | Političari (COCI20_politicari) | C++17 | 17 ms | 2696 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 int long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main(){
fast;
int n,k;
cin>>n>>k;
if(k==1){
cout<<"1"<<endl;
return 0;
}
if(k==2){
cout<<"2"<<endl;
return 0;
}
k-=2;
set<pair<int,int>>s;
vector<pair<int,int>>v;
int arr[n+5][n+5];
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)cin>>arr[i][j];
}
int x=1,y=2;
while(1){
if(s.count({x,y}))break;
s.insert({x,y});
v.pb({x,y});
int z=x;
x=y;
y=arr[y][z];
}
if(k<v.size()){
cout<<v[k].ss<<endl;
return 0;
}
vector<int>v2;
for(int i=0;i<v.size();i++){
if(v[i]==make_pair(x,y)){
k-=i;
for(int j=i;j<v.size();j++){
v2.pb(v[j].ss);
}
break;
}
}
cout<<v2[k%(v2.size())]<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |