# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
544169 | AlperenT | Političari (COCI20_politicari) | C++17 | 18 ms | 4300 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>
using namespace std;
const int N = 500 + 5;
long long n, k, graph[N][N], dist[N][N];
struct Item{
long long a, b;
};
Item cur = {1, 2};
bool flag;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> k;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cin >> graph[i][j];
}
}
if(k == 1) cout << 1;
else{
dist[1][2] = 2, k -= 2;
while(k > 0){
k--;
if(flag) cur = {cur.b, graph[cur.b][cur.a]};
else{
if(dist[cur.b][graph[cur.b][cur.a]] == 0){
dist[cur.b][graph[cur.b][cur.a]] = dist[cur.a][cur.b] + 1;
cur = {cur.b, graph[cur.b][cur.a]};
}
else{
k %= dist[cur.a][cur.b] - dist[cur.b][graph[cur.b][cur.a]] + 1;
cur = {cur.b, graph[cur.b][cur.a]};
flag = true;
}
}
}
}
cout << cur.b;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |