#include <iostream>
#include <vector>
using namespace std;
const int N = 505;
int n, md[N][N], mdc[N][N], ed[N][N], edc[N][N];
vector <int> graph[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
char c;
cin >> n >> c;
for (int i = 0; i < n; i++) {
int m;
do {
cin >> m;
graph[i].push_back(m - 1);
} while (m);
}
for (int sz = 1; sz <= n; sz++) {
for (int i = 0; i < n; i++) {
for (int &B : graph[i]) {
int A = (i + sz) % n;
if ((B + n - i) % n < sz) {
if (md[B][A] > 0 && md[B][A] >= md[i][A]) md[i][A] = md[B][A] + 1;
if (ed[B][A] >= ed[i][A]) ed[i][A] = ed[B][A] + 1;
if (edc[B][i] >= edc[i][A]) edc[i][A] = edc[B][i] + 1;
}
A = (i + n - sz) % n;
if ((i + n - B) % n < sz) {
if (mdc[B][A] > 0 && mdc[B][A] >= mdc[i][A]) mdc[i][A] = mdc[B][A] + 1;
if (edc[B][A] >= edc[i][A]) edc[i][A] = edc[B][A] + 1;
if (ed[B][i] >= ed[i][A]) ed[i][A] = ed[B][i] + 1;
}
}
}
}
int mx = 0, mxi;
for (int i = 0; i < n - 1; i++) {
if (ed[i][i] > mx) {
mx = ed[i][i];
mxi = i;
}
if (edc[i][i] > mx) {
mx = edc[i][i];
mxi = i;
}
}
cout << mx << '\n' << mxi + 1;
return 0;
}
Compilation message
race.cpp: In function 'int main()':
race.cpp:50:30: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | cout << mx << '\n' << mxi + 1;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
476 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
10 |
Incorrect |
6 ms |
964 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
860 KB |
Output isn't correct |
12 |
Incorrect |
12 ms |
1116 KB |
Output isn't correct |
13 |
Incorrect |
21 ms |
1560 KB |
Output isn't correct |
14 |
Incorrect |
38 ms |
2140 KB |
Output isn't correct |
15 |
Incorrect |
121 ms |
2652 KB |
Output isn't correct |
16 |
Incorrect |
149 ms |
2652 KB |
Output isn't correct |
17 |
Incorrect |
120 ms |
2648 KB |
Output isn't correct |
18 |
Incorrect |
50 ms |
2396 KB |
Output isn't correct |
19 |
Incorrect |
174 ms |
2792 KB |
Output isn't correct |
20 |
Incorrect |
174 ms |
2648 KB |
Output isn't correct |