#include <stdio.h>
#define N 500
int main() {
static int kk[N][N], tt[N][N];
int n, i, j, k, t;
long long t_;
scanf("%d%lld", &n, &t_);
if (t_ <= 2) {
printf("%lld\n", t_);
return 0;
}
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
scanf("%d", &kk[i][j]), kk[i][j]--;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
tt[i][j] = -1;
i = 0, j = 1, t = 1;
while (t < t_ && tt[i][j] == -1) {
tt[i][j] = t;
k = kk[j][i], i = j, j = k, t++;
}
if (t != t_) {
t_ = (t_ - t) % (t - tt[i][j]), t = 0;
while (t < t_)
k = kk[j][i], i = j, j = k, t++;
}
printf("%d\n", i + 1);
return 0;
}
Compilation message
politicari.c: In function 'main':
politicari.c:10:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%d%lld", &n, &t_);
| ^~~~~~~~~~~~~~~~~~~~~~~~
politicari.c:17:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d", &kk[i][j]), kk[i][j]--;
| ^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
1100 KB |
Output is correct |
3 |
Correct |
15 ms |
1756 KB |
Output is correct |
4 |
Correct |
23 ms |
1932 KB |
Output is correct |
5 |
Correct |
22 ms |
2200 KB |
Output is correct |
6 |
Correct |
22 ms |
2204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
704 KB |
Output is correct |
9 |
Correct |
6 ms |
1100 KB |
Output is correct |
10 |
Correct |
19 ms |
1996 KB |
Output is correct |
11 |
Correct |
25 ms |
2116 KB |
Output is correct |
12 |
Correct |
24 ms |
2216 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
716 KB |
Output is correct |