# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
340091 | Hazem | Političari (COCI20_politicari) | C++14 | 365 ms | 140416 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.
/*
ID: tmhazem1
LANG: C++14
TASK: pprime
*/
#include <bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define LL long long
const int N = 5e2 + 10;
LL LINF = 100000000000000000;
LL INF = 1000000000;
pair<int,int> nxt[N][N][70];
int main()
{
//freopen("out.txt","w",stdout);
LL n,k;
scanf("%lld%lld",&n,&k);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
int x;cin>>x;
nxt[i][j][0] = {x,i};
}
if(k==1){
puts("1");
return 0;
}
for(int j=1;j<=60;j++)
for(int i=1;i<=n;i++)
for(int k=1;k<=n;k++){
if(k==i)continue;
pair<int,int>p = nxt[i][k][j-1];
nxt[i][k][j] = nxt[p.F][p.S][j-1];
}
k -= 2;
pair<int,int>cur = {2,1};
for(LL i=60;i>=0;i--)
if((1ll<<i)<=k)
cur = nxt[cur.F][cur.S][i],k -= 1ll<<i;
printf("%d\n",cur.F);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |