# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201199 | Ort | Političari (COCI20_politicari) | C++11 | 26 ms | 1400 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 ll long long
using namespace std;
int n;
ll k;
int mt[505][505];
set<pair<int,int> > C;
vector<int> p, R;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin >> mt[i][j];
p.push_back(1);
int start = 2;
int next = 0;
while(true) {
if(C.count(make_pair(p.back(), start))) break;
C.insert(make_pair(p.back(), start));
next = mt[start][p.back()];
p.push_back(start);
start = next;
}
int fst = 1;
for(int i=0;i<p.size()-1;i++) {
if(p[i+1]==next && p[i]==p.back()) break;
fst++;
}
for(int i=fst;i<p.size();i++) R.push_back(p[i]);
if(k==1) cout << 1;
else if(k==2) cout << 2;
else {
if(k<=fst) {
cout << p[k];
return 0;
}
k -= fst; k--;
int md = R.size();
cout << R[k%md];
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |