#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010
#define maxn 500
int n, k;
vector<int> adj[maxn];
int memo[maxn][maxn][2];
int dp(int x, int y, bool onY) {
if (memo[x][y][onY] != -1) return memo[x][y][onY];
int best = 1;
for (int i : adj[onY ? y : x]) {
if (x < y) {
if (x < i && i < y) {
best = max(best, 1 + max(dp(x, i, 1), dp(i, y, 0)));
}
} else {
if (i > x || i < y) {
best = max(best, 1 + max(dp(x, i, 1), dp(i, y, 0)));
}
}
}
return memo[x][y][onY] = best;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k; assert(!k);
F0R(i, n) {
int x;
while (cin >> x && x != 0) {
--x;
adj[i].pb(x);
}
}
int best = -1, bestIdx = -1;
F0R(i, n) F0R(j, n) F0R(k, 2) memo[i][j][k] = -1;
F0R(i, n) {
for (int j : adj[i]) {
int val = max(dp(i, j, 1), dp(j, i, 0));
if (best < val) {
best = val;
bestIdx = i;
}
}
}
cout << best << endl;
cout << bestIdx+1 << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
396 KB |
Output is correct |
2 |
Runtime error |
1 ms |
640 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
3 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
4 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
7 |
Correct |
5 ms |
620 KB |
Output is correct |
8 |
Runtime error |
2 ms |
492 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
9 |
Correct |
5 ms |
748 KB |
Output is correct |
10 |
Correct |
15 ms |
876 KB |
Output is correct |
11 |
Correct |
8 ms |
748 KB |
Output is correct |
12 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
13 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
14 |
Correct |
63 ms |
2028 KB |
Output is correct |
15 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
16 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
17 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
18 |
Correct |
83 ms |
2540 KB |
Output is correct |
19 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
20 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |