#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[101000];
int n, m, D[101000], K, C[101000], w[101000];
void DFS(int a){
int i, r = 0;
C[a] = 1;
for (i = 0; i < E[a].size(); i++){
DFS(E[a][i]);
C[a] += C[E[a][i]];
w[i] = C[E[a][i]] - D[E[a][i]];
r += D[E[a][i]];
}
if (E[a].size() <= K){
D[a] = r;
return;
}
sort(w, w + E[a].size());
for (i = 0; i < E[a].size() - K; i++){
r += w[i];
}
D[a] = r;
}
int main(){
scanf("%d%d", &n, &m);
int i, a, be = 0, ed = n - 1, r;
for (i = 2; i <= n; i++){
scanf("%d", &a);
E[a].push_back(i);
}
while (be <= ed){
K = (be + ed) >> 1;
DFS(1);
if (n - D[1] >= m){
r = K;
ed = K - 1;
}
else be = K + 1;
}
printf("%d\n", r);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4760 KB |
Output is correct |
2 |
Correct |
0 ms |
4760 KB |
Output is correct |
3 |
Correct |
0 ms |
4760 KB |
Output is correct |
4 |
Correct |
0 ms |
4760 KB |
Output is correct |
5 |
Correct |
0 ms |
4760 KB |
Output is correct |
6 |
Correct |
0 ms |
4760 KB |
Output is correct |
7 |
Correct |
0 ms |
4760 KB |
Output is correct |
8 |
Correct |
0 ms |
4760 KB |
Output is correct |
9 |
Correct |
0 ms |
4760 KB |
Output is correct |
10 |
Correct |
0 ms |
4760 KB |
Output is correct |
11 |
Correct |
0 ms |
4760 KB |
Output is correct |
12 |
Incorrect |
0 ms |
4760 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4760 KB |
Output is correct |
2 |
Incorrect |
0 ms |
4760 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4760 KB |
Output is correct |
2 |
Correct |
130 ms |
6740 KB |
Output is correct |
3 |
Correct |
45 ms |
6212 KB |
Output is correct |
4 |
Correct |
49 ms |
6212 KB |
Output is correct |
5 |
Correct |
121 ms |
6740 KB |
Output is correct |
6 |
Correct |
96 ms |
6476 KB |
Output is correct |
7 |
Correct |
94 ms |
6476 KB |
Output is correct |
8 |
Correct |
97 ms |
6344 KB |
Output is correct |
9 |
Correct |
101 ms |
6476 KB |
Output is correct |
10 |
Correct |
80 ms |
6212 KB |
Output is correct |
11 |
Correct |
89 ms |
6344 KB |
Output is correct |
12 |
Correct |
122 ms |
6608 KB |
Output is correct |
13 |
Correct |
117 ms |
6608 KB |
Output is correct |
14 |
Correct |
62 ms |
5948 KB |
Output is correct |
15 |
Correct |
91 ms |
6608 KB |
Output is correct |
16 |
Incorrect |
66 ms |
5948 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4760 KB |
Output is correct |
2 |
Correct |
36 ms |
5336 KB |
Output is correct |
3 |
Correct |
57 ms |
5532 KB |
Output is correct |
4 |
Correct |
55 ms |
6344 KB |
Output is correct |
5 |
Correct |
56 ms |
7664 KB |
Output is correct |
6 |
Correct |
37 ms |
6212 KB |
Output is correct |
7 |
Correct |
65 ms |
13920 KB |
Output is correct |
8 |
Correct |
106 ms |
6476 KB |
Output is correct |
9 |
Correct |
104 ms |
6476 KB |
Output is correct |
10 |
Correct |
79 ms |
6080 KB |
Output is correct |
11 |
Correct |
32 ms |
5288 KB |
Output is correct |
12 |
Correct |
92 ms |
6212 KB |
Output is correct |
13 |
Correct |
62 ms |
5816 KB |
Output is correct |
14 |
Correct |
94 ms |
6212 KB |
Output is correct |
15 |
Correct |
107 ms |
6476 KB |
Output is correct |
16 |
Correct |
47 ms |
5552 KB |
Output is correct |
17 |
Correct |
42 ms |
5552 KB |
Output is correct |
18 |
Correct |
77 ms |
6080 KB |
Output is correct |
19 |
Correct |
77 ms |
6080 KB |
Output is correct |
20 |
Correct |
39 ms |
5420 KB |
Output is correct |
21 |
Correct |
22 ms |
5156 KB |
Output is correct |
22 |
Correct |
26 ms |
8700 KB |
Output is correct |
23 |
Correct |
37 ms |
10292 KB |
Output is correct |
24 |
Correct |
39 ms |
10216 KB |
Output is correct |
25 |
Correct |
28 ms |
6212 KB |
Output is correct |
26 |
Correct |
47 ms |
7268 KB |
Output is correct |
27 |
Correct |
47 ms |
6212 KB |
Output is correct |
28 |
Correct |
30 ms |
5684 KB |
Output is correct |
29 |
Correct |
41 ms |
6080 KB |
Output is correct |
30 |
Correct |
47 ms |
5948 KB |
Output is correct |
31 |
Correct |
43 ms |
5948 KB |
Output is correct |
32 |
Correct |
22 ms |
5156 KB |
Output is correct |
33 |
Correct |
22 ms |
5148 KB |
Output is correct |
34 |
Correct |
18 ms |
5104 KB |
Output is correct |
35 |
Correct |
4 ms |
4760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4760 KB |
Output is correct |
2 |
Correct |
54 ms |
5472 KB |
Output is correct |
3 |
Correct |
53 ms |
5532 KB |
Output is correct |
4 |
Incorrect |
61 ms |
6344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |