#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 1580;
vector<int> edg[MAXN];
int depth[MAXN];
int dp[MAXN][MAXN];
signed main() {
int n, d;
cin >> n >> d;
for (int i = 1; i < n; ++i) {
int rt;
cin >> rt;
edg[rt].push_back(i);
depth[i] = depth[rt] + 1;
}
for (int i = n - 1; i >= 0; --i) {
dp[i][depth[i]] = 1;
if (d + depth[i] < n) {
for (auto u : edg[i]) {
dp[i][depth[i]] += dp[u][d + depth[i]];
}
}
for (int t = depth[i] + 1; t < n; ++t) {
int d0 = min(n, max(t, depth[i] * 2 + d - t));
int mx = 0;
for (auto u : edg[i]) {
dp[i][t] += dp[u][d0];
mx = max(mx, dp[u][t] - dp[u][d0]);
}
dp[i][t] += mx;
}
for (int t = n - 2; t >= 0; --t) {
dp[i][t] = max(dp[i][t], dp[i][t + 1]);
}
//cout << i << ": ";
//for (int j = 0; j < n; ++j)
//cout << dp[i][j] << ' ';
//cout << '\n';
}
cout << dp[0][0] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
17 ms |
9552 KB |
Output is correct |
22 |
Correct |
5 ms |
3268 KB |
Output is correct |
23 |
Correct |
4 ms |
3276 KB |
Output is correct |
24 |
Correct |
4 ms |
3284 KB |
Output is correct |
25 |
Correct |
10 ms |
6512 KB |
Output is correct |
26 |
Correct |
10 ms |
6480 KB |
Output is correct |
27 |
Correct |
10 ms |
6476 KB |
Output is correct |
28 |
Correct |
19 ms |
9508 KB |
Output is correct |
29 |
Correct |
19 ms |
9548 KB |
Output is correct |
30 |
Correct |
19 ms |
9548 KB |
Output is correct |
31 |
Correct |
20 ms |
9532 KB |
Output is correct |
32 |
Correct |
19 ms |
9332 KB |
Output is correct |
33 |
Correct |
21 ms |
9352 KB |
Output is correct |
34 |
Correct |
18 ms |
8896 KB |
Output is correct |
35 |
Correct |
21 ms |
8908 KB |
Output is correct |
36 |
Correct |
19 ms |
9540 KB |
Output is correct |
37 |
Correct |
19 ms |
9596 KB |
Output is correct |
38 |
Correct |
20 ms |
9548 KB |
Output is correct |
39 |
Correct |
18 ms |
9616 KB |
Output is correct |
40 |
Correct |
16 ms |
9560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
17 ms |
9552 KB |
Output is correct |
22 |
Correct |
5 ms |
3268 KB |
Output is correct |
23 |
Correct |
4 ms |
3276 KB |
Output is correct |
24 |
Correct |
4 ms |
3284 KB |
Output is correct |
25 |
Correct |
10 ms |
6512 KB |
Output is correct |
26 |
Correct |
10 ms |
6480 KB |
Output is correct |
27 |
Correct |
10 ms |
6476 KB |
Output is correct |
28 |
Correct |
19 ms |
9508 KB |
Output is correct |
29 |
Correct |
19 ms |
9548 KB |
Output is correct |
30 |
Correct |
19 ms |
9548 KB |
Output is correct |
31 |
Correct |
20 ms |
9532 KB |
Output is correct |
32 |
Correct |
19 ms |
9332 KB |
Output is correct |
33 |
Correct |
21 ms |
9352 KB |
Output is correct |
34 |
Correct |
18 ms |
8896 KB |
Output is correct |
35 |
Correct |
21 ms |
8908 KB |
Output is correct |
36 |
Correct |
19 ms |
9540 KB |
Output is correct |
37 |
Correct |
19 ms |
9596 KB |
Output is correct |
38 |
Correct |
20 ms |
9548 KB |
Output is correct |
39 |
Correct |
18 ms |
9616 KB |
Output is correct |
40 |
Correct |
16 ms |
9560 KB |
Output is correct |
41 |
Runtime error |
1 ms |
588 KB |
Execution killed with signal 11 |
42 |
Halted |
0 ms |
0 KB |
- |