# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883810 | vjudge1 | Političari (COCI20_politicari) | C++17 | 239 ms | 124660 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;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
void solve() {
int n,k;
cin >> n >> k;
vector<vi> a(n+1,vi(n+1));
F(i,n) F(j,n) cin >> a[i][j];
if (k == 1) {
cout << 1 << endl;
return;
}
int up[n*n+1][62];
memset(up,0,sizeof up);
F(i,n) {
F(j,n) {
if (i == j) continue;
int idx = (i-1)*n+j;
up[idx][0] = (a[i][j]-1)*n+i;
}
}
for (int i=1;i<62;i++) {
for (int j=1;j<=n*n;j++) {
up[j][i] = up[up[j][i-1]][i-1];
}
}
int ans = n+1;
for (int i=0;i<62;i++) {
if ((k-2)&(1LL<<i)) ans = up[ans][i];
}
cout << (ans+n-1)/n << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t = 1;
//cin >> t;
F(i,t) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |