Submission #736150

#TimeUsernameProblemLanguageResultExecution timeMemory
736150marvinthangPolitičari (COCI20_politicari)C++17
70 / 70
251 ms119948 KiB
/****************************** * author : @marvinthang * * date : 14 / 11 / 2021 * ******************************/ #include <bits/stdc++.h> using namespace std; #define superspeed ios_base::sync_with_stdio(false);\ cin.tie(NULL);\ //cout.tie(NULL); #define file(name) freopen(name".inp", "r", stdin);\ freopen(name".out", "w", stdout); const int MOD = 1e9 + 7; // 998244353; const double PI = 3.1415926535897932384626433832795; // acos((db)-1); atan(-1.0); const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; const long long oo = 1e18; const int MAX = 505; const int LOG = 60; int N; pair <int, int> rmq[MAX][MAX][LOG]; long long K; int main() { superspeed; cin >> N >> K; if (K <= 2) { cout << K; return 0; } K -= 2; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { cin >> rmq[i][j][0].first; rmq[i][j][0].second = i; } } for (int k = 1; k < LOG; ++k) { for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { pair <int, int> tmp = rmq[i][j][k - 1]; rmq[i][j][k] = rmq[tmp.first][tmp.second][k - 1]; } } } // cout << rmq[1][2][0].second << '\n'; pair <int, int> res = {2, 1}; for (int k = 0; k < LOG; ++k) { if ((K >> k) & 1) res = rmq[res.first][res.second][k]; // cout << res.first << ' ' << res.second << '\n'; } cout << res.first; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...