# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
209988 | SamAnd | Političari (COCI20_politicari) | C++17 | 38 ms | 2424 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 m_p make_pair
const int N = 502;
int n;
long long k;
int a[N][N];
bool c[N][N];
int main()
{
scanf("%d%lld", &n, &k);
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j)
{
scanf("%d", &a[i][j]);
}
}
if (k == 1)
{
printf("1\n");
return 0;
}
k -= 2;
vector<pair<int, int> > v;
pair<int, int> u = m_p(2, 1);
c[u.first][u.second] = true;
v.push_back(u);
while (k--)
{
pair<int, int> h = m_p(a[u.first][u.second], u.first);
if (c[h.first][h.second])
{
for (int i = 0; i < v.size(); ++i)
{
if (v[i] == h)
{
k %= (v.size() - i);
printf("%d\n", v[i + k].first);
return 0;
}
}
}
u = h;
c[u.first][u.second] = true;
v.push_back(u);
}
printf("%d\n", u.first);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |