Submission #18505

# Submission time Handle Problem Language Result Execution time Memory
18505 2016-02-07T06:31:50 Z suhgyuho_william Company Planning (TOKI14_company) C++
100 / 100
356 ms 14276 KB
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int N,M,K;
vector<int> edge[100002];

int dfs(int x){
	int i,v,sum;
	priority_queue<int> q;

	for(i=0; i<edge[x].size(); i++){
		v = edge[x][i];
		q.push(dfs(v));
	}
	i = K;
	sum = 1;
	while(i > 0 && !q.empty()){
		sum += q.top();
		q.pop();
		i--;
	}
	return sum;
}

bool checking(){
	if(dfs(1) >= M) return true;
	return false;
}

int main(){
	int i,ans;
	int l,mid,r;
	//freopen("input.txt","r",stdin);

	scanf("%d %d",&N,&M);
	for(i=1; i<N; i++){
		scanf("%d",&ans);
		edge[ans].push_back(i+1);
	}
	l = 0; r = N-1;
	while(l <= r){
		mid = (l+r)/2;
		K = mid;
		if(checking()){
			ans = mid;
			r = mid-1;
		}else l = mid+1;
	}
	printf("%d",ans);

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 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 2 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 0 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 0 ms 3552 KB Output is correct
3 Correct 3 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 2 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 2 ms 3552 KB Output is correct
17 Correct 3 ms 3552 KB Output is correct
18 Correct 0 ms 3552 KB Output is correct
19 Correct 2 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 2 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 0 ms 3552 KB Output is correct
30 Correct 0 ms 3552 KB Output is correct
31 Correct 0 ms 3552 KB Output is correct
32 Correct 2 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 354 ms 5532 KB Output is correct
3 Correct 160 ms 5004 KB Output is correct
4 Correct 155 ms 5004 KB Output is correct
5 Correct 356 ms 5532 KB Output is correct
6 Correct 305 ms 5268 KB Output is correct
7 Correct 275 ms 5268 KB Output is correct
8 Correct 270 ms 5136 KB Output is correct
9 Correct 290 ms 5268 KB Output is correct
10 Correct 233 ms 5004 KB Output is correct
11 Correct 267 ms 5136 KB Output is correct
12 Correct 349 ms 5400 KB Output is correct
13 Correct 330 ms 5400 KB Output is correct
14 Correct 159 ms 4740 KB Output is correct
15 Correct 298 ms 5400 KB Output is correct
16 Correct 170 ms 4740 KB Output is correct
17 Correct 249 ms 5136 KB Output is correct
18 Correct 100 ms 4476 KB Output is correct
19 Correct 54 ms 4080 KB Output is correct
20 Correct 121 ms 4740 KB Output is correct
21 Correct 89 ms 4476 KB Output is correct
22 Correct 32 ms 3948 KB Output is correct
23 Correct 124 ms 4740 KB Output is correct
24 Correct 133 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 164 ms 4384 KB Output is correct
3 Correct 200 ms 5092 KB Output is correct
4 Correct 223 ms 5136 KB Output is correct
5 Correct 170 ms 6456 KB Output is correct
6 Correct 150 ms 5004 KB Output is correct
7 Correct 170 ms 14276 KB Output is correct
8 Correct 323 ms 5268 KB Output is correct
9 Correct 340 ms 5268 KB Output is correct
10 Correct 244 ms 4872 KB Output is correct
11 Correct 72 ms 4080 KB Output is correct
12 Correct 289 ms 5004 KB Output is correct
13 Correct 170 ms 4608 KB Output is correct
14 Correct 288 ms 5004 KB Output is correct
15 Correct 332 ms 5268 KB Output is correct
16 Correct 120 ms 4344 KB Output is correct
17 Correct 107 ms 4344 KB Output is correct
18 Correct 216 ms 4872 KB Output is correct
19 Correct 245 ms 4872 KB Output is correct
20 Correct 88 ms 4212 KB Output is correct
21 Correct 43 ms 3948 KB Output is correct
22 Correct 61 ms 8176 KB Output is correct
23 Correct 93 ms 10040 KB Output is correct
24 Correct 84 ms 9936 KB Output is correct
25 Correct 74 ms 5004 KB Output is correct
26 Correct 145 ms 6060 KB Output is correct
27 Correct 145 ms 5004 KB Output is correct
28 Correct 96 ms 4476 KB Output is correct
29 Correct 119 ms 4872 KB Output is correct
30 Correct 158 ms 4740 KB Output is correct
31 Correct 158 ms 4740 KB Output is correct
32 Correct 44 ms 3948 KB Output is correct
33 Correct 68 ms 4324 KB Output is correct
34 Correct 61 ms 3896 KB Output is correct
35 Correct 9 ms 3552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3552 KB Output is correct
2 Correct 66 ms 4392 KB Output is correct
3 Correct 159 ms 5092 KB Output is correct
4 Correct 209 ms 5136 KB Output is correct
5 Correct 171 ms 6456 KB Output is correct
6 Correct 154 ms 5004 KB Output is correct
7 Correct 169 ms 14272 KB Output is correct
8 Correct 326 ms 5268 KB Output is correct
9 Correct 174 ms 4648 KB Output is correct
10 Correct 186 ms 5092 KB Output is correct
11 Correct 217 ms 5136 KB Output is correct
12 Correct 173 ms 6456 KB Output is correct
13 Correct 151 ms 5004 KB Output is correct
14 Correct 157 ms 14272 KB Output is correct
15 Correct 331 ms 5268 KB Output is correct
16 Correct 343 ms 5268 KB Output is correct
17 Correct 351 ms 5268 KB Output is correct
18 Correct 330 ms 5136 KB Output is correct
19 Correct 234 ms 4872 KB Output is correct
20 Correct 206 ms 4740 KB Output is correct
21 Correct 222 ms 4872 KB Output is correct
22 Correct 43 ms 3948 KB Output is correct
23 Correct 205 ms 4740 KB Output is correct
24 Correct 68 ms 4080 KB Output is correct
25 Correct 94 ms 4344 KB Output is correct
26 Correct 121 ms 4344 KB Output is correct
27 Correct 295 ms 5004 KB Output is correct
28 Correct 318 ms 5136 KB Output is correct
29 Correct 307 ms 5136 KB Output is correct
30 Correct 21 ms 3684 KB Output is correct
31 Correct 44 ms 3816 KB Output is correct
32 Correct 326 ms 5136 KB Output is correct
33 Correct 296 ms 5004 KB Output is correct
34 Correct 46 ms 3948 KB Output is correct
35 Correct 318 ms 5136 KB Output is correct
36 Correct 324 ms 5268 KB Output is correct
37 Correct 247 ms 4872 KB Output is correct
38 Correct 198 ms 4740 KB Output is correct
39 Correct 311 ms 5136 KB Output is correct
40 Correct 18 ms 3684 KB Output is correct
41 Correct 95 ms 4212 KB Output is correct
42 Correct 135 ms 12428 KB Output is correct
43 Correct 59 ms 7708 KB Output is correct
44 Correct 95 ms 10192 KB Output is correct
45 Correct 136 ms 6060 KB Output is correct
46 Correct 29 ms 4212 KB Output is correct
47 Correct 101 ms 10616 KB Output is correct
48 Correct 127 ms 12712 KB Output is correct
49 Correct 153 ms 13888 KB Output is correct
50 Correct 158 ms 6192 KB Output is correct
51 Correct 77 ms 5004 KB Output is correct
52 Correct 112 ms 4608 KB Output is correct
53 Correct 119 ms 4740 KB Output is correct
54 Correct 70 ms 4212 KB Output is correct
55 Correct 151 ms 4740 KB Output is correct
56 Correct 108 ms 4344 KB Output is correct
57 Correct 246 ms 5136 KB Output is correct
58 Correct 64 ms 4212 KB Output is correct
59 Correct 81 ms 4344 KB Output is correct
60 Correct 129 ms 4872 KB Output is correct
61 Correct 62 ms 4080 KB Output is correct
62 Correct 113 ms 4476 KB Output is correct
63 Correct 92 ms 4476 KB Output is correct
64 Correct 113 ms 5092 KB Output is correct
65 Correct 174 ms 5092 KB Output is correct
66 Correct 43 ms 4144 KB Output is correct
67 Correct 36 ms 4156 KB Output is correct
68 Correct 90 ms 4320 KB Output is correct
69 Correct 52 ms 3872 KB Output is correct
70 Correct 134 ms 4544 KB Output is correct
71 Correct 64 ms 4008 KB Output is correct
72 Correct 0 ms 3552 KB Output is correct