#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> graph[100005];
int n,m;
int lim;
int solve(int x){
vector<int> ret;
for (int i=0; i<graph[x].size(); i++) {
ret.push_back(solve(graph[x][i]));
}
sort(ret.begin(),ret.end());
reverse(ret.begin(),ret.end());
int res = 0;
for (int i=0; i<lim && i < ret.size(); i++) {
res += ret[i];
}
return res + 1;
}
bool trial(int x){
lim = x;
return solve(1) >= m;
}
int main(){
scanf("%d %d",&n,&m);
for (int i=2; i<=n; i++) {
int t;
scanf("%d",&t);
graph[t].push_back(i);
}
int s = 0, e = n;
while (s != e) {
int m = (s+e)/2;
if(trial(m)) e = m;
else s = m+1;
}
printf("%d",s);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3552 KB |
Output is correct |
2 |
Correct |
0 ms |
3552 KB |
Output is correct |
3 |
Correct |
0 ms |
3552 KB |
Output is correct |
4 |
Correct |
0 ms |
3552 KB |
Output is correct |
5 |
Correct |
0 ms |
3552 KB |
Output is correct |
6 |
Correct |
0 ms |
3552 KB |
Output is correct |
7 |
Correct |
0 ms |
3552 KB |
Output is correct |
8 |
Correct |
0 ms |
3552 KB |
Output is correct |
9 |
Correct |
0 ms |
3552 KB |
Output is correct |
10 |
Correct |
0 ms |
3552 KB |
Output is correct |
11 |
Correct |
0 ms |
3552 KB |
Output is correct |
12 |
Correct |
0 ms |
3552 KB |
Output is correct |
13 |
Correct |
0 ms |
3552 KB |
Output is correct |
14 |
Correct |
0 ms |
3552 KB |
Output is correct |
15 |
Correct |
0 ms |
3552 KB |
Output is correct |
16 |
Correct |
0 ms |
3552 KB |
Output is correct |
17 |
Correct |
0 ms |
3552 KB |
Output is correct |
18 |
Correct |
0 ms |
3552 KB |
Output is correct |
19 |
Correct |
0 ms |
3552 KB |
Output is correct |
20 |
Correct |
2 ms |
3552 KB |
Output is correct |
21 |
Correct |
0 ms |
3552 KB |
Output is correct |
22 |
Correct |
0 ms |
3552 KB |
Output is correct |
23 |
Correct |
0 ms |
3552 KB |
Output is correct |
24 |
Correct |
0 ms |
3552 KB |
Output is correct |
25 |
Correct |
0 ms |
3552 KB |
Output is correct |
26 |
Correct |
0 ms |
3552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3552 KB |
Output is correct |
2 |
Correct |
3 ms |
3552 KB |
Output is correct |
3 |
Correct |
0 ms |
3552 KB |
Output is correct |
4 |
Correct |
2 ms |
3552 KB |
Output is correct |
5 |
Correct |
0 ms |
3552 KB |
Output is correct |
6 |
Correct |
0 ms |
3552 KB |
Output is correct |
7 |
Correct |
0 ms |
3552 KB |
Output is correct |
8 |
Correct |
2 ms |
3552 KB |
Output is correct |
9 |
Correct |
2 ms |
3552 KB |
Output is correct |
10 |
Correct |
0 ms |
3552 KB |
Output is correct |
11 |
Correct |
0 ms |
3552 KB |
Output is correct |
12 |
Correct |
0 ms |
3552 KB |
Output is correct |
13 |
Correct |
0 ms |
3552 KB |
Output is correct |
14 |
Correct |
3 ms |
3552 KB |
Output is correct |
15 |
Correct |
2 ms |
3552 KB |
Output is correct |
16 |
Correct |
2 ms |
3552 KB |
Output is correct |
17 |
Correct |
0 ms |
3552 KB |
Output is correct |
18 |
Correct |
2 ms |
3552 KB |
Output is correct |
19 |
Correct |
0 ms |
3552 KB |
Output is correct |
20 |
Correct |
0 ms |
3552 KB |
Output is correct |
21 |
Correct |
0 ms |
3552 KB |
Output is correct |
22 |
Correct |
2 ms |
3552 KB |
Output is correct |
23 |
Correct |
0 ms |
3552 KB |
Output is correct |
24 |
Correct |
0 ms |
3552 KB |
Output is correct |
25 |
Correct |
0 ms |
3552 KB |
Output is correct |
26 |
Correct |
0 ms |
3552 KB |
Output is correct |
27 |
Correct |
0 ms |
3552 KB |
Output is correct |
28 |
Correct |
0 ms |
3552 KB |
Output is correct |
29 |
Correct |
2 ms |
3552 KB |
Output is correct |
30 |
Correct |
2 ms |
3552 KB |
Output is correct |
31 |
Correct |
2 ms |
3552 KB |
Output is correct |
32 |
Correct |
0 ms |
3552 KB |
Output is correct |
33 |
Correct |
0 ms |
3552 KB |
Output is correct |
34 |
Correct |
0 ms |
3552 KB |
Output is correct |
35 |
Correct |
0 ms |
3552 KB |
Output is correct |
36 |
Correct |
0 ms |
3552 KB |
Output is correct |
37 |
Correct |
0 ms |
3552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3552 KB |
Output is correct |
2 |
Correct |
244 ms |
5532 KB |
Output is correct |
3 |
Correct |
146 ms |
5004 KB |
Output is correct |
4 |
Correct |
138 ms |
5004 KB |
Output is correct |
5 |
Correct |
247 ms |
5532 KB |
Output is correct |
6 |
Correct |
218 ms |
5268 KB |
Output is correct |
7 |
Correct |
207 ms |
5268 KB |
Output is correct |
8 |
Correct |
193 ms |
5136 KB |
Output is correct |
9 |
Correct |
208 ms |
5268 KB |
Output is correct |
10 |
Correct |
176 ms |
5004 KB |
Output is correct |
11 |
Correct |
190 ms |
5136 KB |
Output is correct |
12 |
Correct |
246 ms |
5400 KB |
Output is correct |
13 |
Correct |
227 ms |
5400 KB |
Output is correct |
14 |
Correct |
127 ms |
4740 KB |
Output is correct |
15 |
Correct |
217 ms |
5400 KB |
Output is correct |
16 |
Correct |
131 ms |
4740 KB |
Output is correct |
17 |
Correct |
175 ms |
5136 KB |
Output is correct |
18 |
Correct |
94 ms |
4476 KB |
Output is correct |
19 |
Correct |
53 ms |
4080 KB |
Output is correct |
20 |
Correct |
115 ms |
4740 KB |
Output is correct |
21 |
Correct |
82 ms |
4476 KB |
Output is correct |
22 |
Correct |
34 ms |
3948 KB |
Output is correct |
23 |
Correct |
106 ms |
4740 KB |
Output is correct |
24 |
Correct |
131 ms |
4872 KB |
Output is correct |
25 |
Correct |
0 ms |
3552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3552 KB |
Output is correct |
2 |
Correct |
52 ms |
4384 KB |
Output is correct |
3 |
Correct |
49 ms |
5092 KB |
Output is correct |
4 |
Correct |
172 ms |
5136 KB |
Output is correct |
5 |
Correct |
169 ms |
6456 KB |
Output is correct |
6 |
Correct |
144 ms |
5004 KB |
Output is correct |
7 |
Correct |
171 ms |
14272 KB |
Output is correct |
8 |
Correct |
221 ms |
5268 KB |
Output is correct |
9 |
Correct |
229 ms |
5268 KB |
Output is correct |
10 |
Correct |
173 ms |
4872 KB |
Output is correct |
11 |
Correct |
67 ms |
4080 KB |
Output is correct |
12 |
Correct |
194 ms |
5004 KB |
Output is correct |
13 |
Correct |
137 ms |
4608 KB |
Output is correct |
14 |
Correct |
198 ms |
5004 KB |
Output is correct |
15 |
Correct |
231 ms |
5268 KB |
Output is correct |
16 |
Correct |
108 ms |
4344 KB |
Output is correct |
17 |
Correct |
94 ms |
4344 KB |
Output is correct |
18 |
Correct |
164 ms |
4872 KB |
Output is correct |
19 |
Correct |
172 ms |
4872 KB |
Output is correct |
20 |
Correct |
76 ms |
4212 KB |
Output is correct |
21 |
Correct |
48 ms |
3948 KB |
Output is correct |
22 |
Correct |
72 ms |
8180 KB |
Output is correct |
23 |
Correct |
89 ms |
10040 KB |
Output is correct |
24 |
Correct |
99 ms |
9940 KB |
Output is correct |
25 |
Correct |
82 ms |
5004 KB |
Output is correct |
26 |
Correct |
144 ms |
6060 KB |
Output is correct |
27 |
Correct |
130 ms |
5004 KB |
Output is correct |
28 |
Correct |
84 ms |
4476 KB |
Output is correct |
29 |
Correct |
113 ms |
4872 KB |
Output is correct |
30 |
Correct |
127 ms |
4740 KB |
Output is correct |
31 |
Correct |
121 ms |
4740 KB |
Output is correct |
32 |
Correct |
40 ms |
3948 KB |
Output is correct |
33 |
Correct |
18 ms |
4324 KB |
Output is correct |
34 |
Correct |
20 ms |
3896 KB |
Output is correct |
35 |
Correct |
6 ms |
3552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3552 KB |
Output is correct |
2 |
Correct |
51 ms |
4392 KB |
Output is correct |
3 |
Correct |
49 ms |
5092 KB |
Output is correct |
4 |
Correct |
162 ms |
5136 KB |
Output is correct |
5 |
Correct |
171 ms |
6456 KB |
Output is correct |
6 |
Correct |
140 ms |
5004 KB |
Output is correct |
7 |
Correct |
165 ms |
14276 KB |
Output is correct |
8 |
Correct |
245 ms |
5268 KB |
Output is correct |
9 |
Correct |
56 ms |
4648 KB |
Output is correct |
10 |
Correct |
55 ms |
5092 KB |
Output is correct |
11 |
Correct |
174 ms |
5136 KB |
Output is correct |
12 |
Correct |
163 ms |
6456 KB |
Output is correct |
13 |
Correct |
137 ms |
5004 KB |
Output is correct |
14 |
Correct |
174 ms |
14276 KB |
Output is correct |
15 |
Correct |
236 ms |
5268 KB |
Output is correct |
16 |
Correct |
238 ms |
5268 KB |
Output is correct |
17 |
Correct |
236 ms |
5268 KB |
Output is correct |
18 |
Correct |
239 ms |
5136 KB |
Output is correct |
19 |
Correct |
179 ms |
4872 KB |
Output is correct |
20 |
Correct |
153 ms |
4740 KB |
Output is correct |
21 |
Correct |
165 ms |
4872 KB |
Output is correct |
22 |
Correct |
47 ms |
3948 KB |
Output is correct |
23 |
Correct |
159 ms |
4740 KB |
Output is correct |
24 |
Correct |
64 ms |
4080 KB |
Output is correct |
25 |
Correct |
90 ms |
4344 KB |
Output is correct |
26 |
Correct |
96 ms |
4344 KB |
Output is correct |
27 |
Correct |
196 ms |
5004 KB |
Output is correct |
28 |
Correct |
204 ms |
5136 KB |
Output is correct |
29 |
Correct |
344 ms |
5136 KB |
Output is correct |
30 |
Correct |
20 ms |
3684 KB |
Output is correct |
31 |
Correct |
39 ms |
3816 KB |
Output is correct |
32 |
Correct |
216 ms |
5136 KB |
Output is correct |
33 |
Correct |
199 ms |
5004 KB |
Output is correct |
34 |
Correct |
40 ms |
3948 KB |
Output is correct |
35 |
Correct |
229 ms |
5136 KB |
Output is correct |
36 |
Correct |
228 ms |
5268 KB |
Output is correct |
37 |
Correct |
182 ms |
4872 KB |
Output is correct |
38 |
Correct |
153 ms |
4740 KB |
Output is correct |
39 |
Correct |
215 ms |
5136 KB |
Output is correct |
40 |
Correct |
13 ms |
3684 KB |
Output is correct |
41 |
Correct |
85 ms |
4212 KB |
Output is correct |
42 |
Correct |
138 ms |
12432 KB |
Output is correct |
43 |
Correct |
61 ms |
7716 KB |
Output is correct |
44 |
Correct |
103 ms |
10196 KB |
Output is correct |
45 |
Correct |
138 ms |
6060 KB |
Output is correct |
46 |
Correct |
31 ms |
4212 KB |
Output is correct |
47 |
Correct |
112 ms |
10616 KB |
Output is correct |
48 |
Correct |
144 ms |
12712 KB |
Output is correct |
49 |
Correct |
167 ms |
13888 KB |
Output is correct |
50 |
Correct |
147 ms |
6192 KB |
Output is correct |
51 |
Correct |
78 ms |
5004 KB |
Output is correct |
52 |
Correct |
102 ms |
4608 KB |
Output is correct |
53 |
Correct |
110 ms |
4740 KB |
Output is correct |
54 |
Correct |
60 ms |
4212 KB |
Output is correct |
55 |
Correct |
117 ms |
4740 KB |
Output is correct |
56 |
Correct |
91 ms |
4344 KB |
Output is correct |
57 |
Correct |
177 ms |
5136 KB |
Output is correct |
58 |
Correct |
61 ms |
4212 KB |
Output is correct |
59 |
Correct |
68 ms |
4344 KB |
Output is correct |
60 |
Correct |
111 ms |
4872 KB |
Output is correct |
61 |
Correct |
57 ms |
4080 KB |
Output is correct |
62 |
Correct |
94 ms |
4476 KB |
Output is correct |
63 |
Correct |
90 ms |
4476 KB |
Output is correct |
64 |
Correct |
42 ms |
5092 KB |
Output is correct |
65 |
Correct |
56 ms |
5092 KB |
Output is correct |
66 |
Correct |
25 ms |
4144 KB |
Output is correct |
67 |
Correct |
24 ms |
4156 KB |
Output is correct |
68 |
Correct |
42 ms |
4320 KB |
Output is correct |
69 |
Correct |
24 ms |
3872 KB |
Output is correct |
70 |
Correct |
41 ms |
4544 KB |
Output is correct |
71 |
Correct |
22 ms |
4008 KB |
Output is correct |
72 |
Correct |
0 ms |
3552 KB |
Output is correct |