Submission #544170

#TimeUsernameProblemLanguageResultExecution timeMemory
544170AlperenTPolitičari (COCI20_politicari)C++17
70 / 70
17 ms3460 KiB
#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 timeMemoryGrader output
Fetching results...