#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>con[100010];
int ch[100010],maxi,arr[100010],t,n,m,par[100010],d[100010],num[100010];
void dfs(int x,int k)
{
int i;
for(i=0;i<con[x].size();i++){
dfs(con[x][i],k);
}
t=0; d[x]=0;
for(i=0;i<con[x].size();i++){
arr[++t]=d[con[x][i]]-num[con[x][i]];
d[x]+=num[con[x][i]];
}
sort(arr+1,arr+t+1);
for(i=1;i<=min(k,t);i++) d[x]+=arr[i];
}
int pro(int x){
dfs(1,x);
return n-d[1];
}
void bsearch()
{
int st=1,en=n,mid;
while(st!=en){
mid=(st+en)/2;
if(pro(mid)>=m) en=mid;
else st=mid+1;
}
printf("%d",st);
}
void init(int x)
{
int i,b;
for(i=0;i<con[x].size();i++){
init(con[x][i]);
num[x]+=num[con[x][i]];
}
num[x]++;
}
int main()
{
int i;
scanf("%d %d",&n,&m);
for(i=2;i<=n;i++){
scanf("%d",&par[i]);
con[par[i]].push_back(i);
}
if(n==1 || m==0){printf("0"); return 0;}
init(1);
bsearch();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5512 KB |
Output is correct |
2 |
Correct |
0 ms |
5512 KB |
Output is correct |
3 |
Correct |
0 ms |
5512 KB |
Output is correct |
4 |
Correct |
0 ms |
5512 KB |
Output is correct |
5 |
Correct |
0 ms |
5512 KB |
Output is correct |
6 |
Correct |
0 ms |
5512 KB |
Output is correct |
7 |
Correct |
1 ms |
5512 KB |
Output is correct |
8 |
Correct |
0 ms |
5512 KB |
Output is correct |
9 |
Correct |
0 ms |
5512 KB |
Output is correct |
10 |
Correct |
0 ms |
5512 KB |
Output is correct |
11 |
Correct |
0 ms |
5512 KB |
Output is correct |
12 |
Correct |
0 ms |
5512 KB |
Output is correct |
13 |
Correct |
0 ms |
5512 KB |
Output is correct |
14 |
Correct |
0 ms |
5512 KB |
Output is correct |
15 |
Correct |
0 ms |
5512 KB |
Output is correct |
16 |
Correct |
0 ms |
5512 KB |
Output is correct |
17 |
Correct |
0 ms |
5512 KB |
Output is correct |
18 |
Correct |
0 ms |
5512 KB |
Output is correct |
19 |
Correct |
0 ms |
5512 KB |
Output is correct |
20 |
Correct |
0 ms |
5512 KB |
Output is correct |
21 |
Correct |
0 ms |
5512 KB |
Output is correct |
22 |
Correct |
0 ms |
5512 KB |
Output is correct |
23 |
Correct |
0 ms |
5512 KB |
Output is correct |
24 |
Correct |
0 ms |
5512 KB |
Output is correct |
25 |
Correct |
0 ms |
5512 KB |
Output is correct |
26 |
Incorrect |
0 ms |
5512 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5512 KB |
Output is correct |
2 |
Correct |
2 ms |
5512 KB |
Output is correct |
3 |
Correct |
2 ms |
5512 KB |
Output is correct |
4 |
Correct |
2 ms |
5512 KB |
Output is correct |
5 |
Correct |
2 ms |
5512 KB |
Output is correct |
6 |
Correct |
0 ms |
5512 KB |
Output is correct |
7 |
Correct |
0 ms |
5512 KB |
Output is correct |
8 |
Correct |
0 ms |
5512 KB |
Output is correct |
9 |
Correct |
0 ms |
5512 KB |
Output is correct |
10 |
Correct |
0 ms |
5512 KB |
Output is correct |
11 |
Correct |
0 ms |
5512 KB |
Output is correct |
12 |
Correct |
1 ms |
5512 KB |
Output is correct |
13 |
Correct |
0 ms |
5512 KB |
Output is correct |
14 |
Correct |
0 ms |
5512 KB |
Output is correct |
15 |
Correct |
1 ms |
5512 KB |
Output is correct |
16 |
Correct |
0 ms |
5512 KB |
Output is correct |
17 |
Correct |
0 ms |
5512 KB |
Output is correct |
18 |
Correct |
0 ms |
5512 KB |
Output is correct |
19 |
Correct |
0 ms |
5512 KB |
Output is correct |
20 |
Correct |
0 ms |
5512 KB |
Output is correct |
21 |
Correct |
0 ms |
5512 KB |
Output is correct |
22 |
Correct |
0 ms |
5512 KB |
Output is correct |
23 |
Correct |
0 ms |
5512 KB |
Output is correct |
24 |
Correct |
0 ms |
5512 KB |
Output is correct |
25 |
Correct |
0 ms |
5512 KB |
Output is correct |
26 |
Correct |
0 ms |
5512 KB |
Output is correct |
27 |
Correct |
0 ms |
5512 KB |
Output is correct |
28 |
Correct |
0 ms |
5512 KB |
Output is correct |
29 |
Correct |
0 ms |
5512 KB |
Output is correct |
30 |
Correct |
1 ms |
5512 KB |
Output is correct |
31 |
Correct |
1 ms |
5512 KB |
Output is correct |
32 |
Correct |
0 ms |
5512 KB |
Output is correct |
33 |
Correct |
0 ms |
5512 KB |
Output is correct |
34 |
Correct |
0 ms |
5512 KB |
Output is correct |
35 |
Correct |
0 ms |
5512 KB |
Output is correct |
36 |
Correct |
0 ms |
5512 KB |
Output is correct |
37 |
Incorrect |
0 ms |
5512 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5512 KB |
Output is correct |
2 |
Correct |
142 ms |
7492 KB |
Output is correct |
3 |
Correct |
45 ms |
6964 KB |
Output is correct |
4 |
Correct |
61 ms |
6964 KB |
Output is correct |
5 |
Correct |
157 ms |
7492 KB |
Output is correct |
6 |
Correct |
137 ms |
7228 KB |
Output is correct |
7 |
Correct |
135 ms |
7228 KB |
Output is correct |
8 |
Correct |
126 ms |
7096 KB |
Output is correct |
9 |
Correct |
147 ms |
7228 KB |
Output is correct |
10 |
Correct |
110 ms |
6964 KB |
Output is correct |
11 |
Correct |
120 ms |
7096 KB |
Output is correct |
12 |
Correct |
139 ms |
7360 KB |
Output is correct |
13 |
Correct |
155 ms |
7360 KB |
Output is correct |
14 |
Correct |
77 ms |
6700 KB |
Output is correct |
15 |
Correct |
138 ms |
7360 KB |
Output is correct |
16 |
Correct |
78 ms |
6700 KB |
Output is correct |
17 |
Correct |
114 ms |
7096 KB |
Output is correct |
18 |
Correct |
57 ms |
6436 KB |
Output is correct |
19 |
Correct |
17 ms |
6040 KB |
Output is correct |
20 |
Correct |
49 ms |
6700 KB |
Output is correct |
21 |
Correct |
31 ms |
6436 KB |
Output is correct |
22 |
Correct |
9 ms |
5908 KB |
Output is correct |
23 |
Correct |
41 ms |
6700 KB |
Output is correct |
24 |
Correct |
55 ms |
6832 KB |
Output is correct |
25 |
Incorrect |
0 ms |
5512 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5512 KB |
Output is correct |
2 |
Correct |
56 ms |
6088 KB |
Output is correct |
3 |
Correct |
69 ms |
6284 KB |
Output is correct |
4 |
Correct |
75 ms |
7096 KB |
Output is correct |
5 |
Correct |
86 ms |
8416 KB |
Output is correct |
6 |
Correct |
60 ms |
6964 KB |
Output is correct |
7 |
Correct |
78 ms |
13108 KB |
Output is correct |
8 |
Correct |
151 ms |
7228 KB |
Output is correct |
9 |
Correct |
131 ms |
7228 KB |
Output is correct |
10 |
Correct |
112 ms |
6832 KB |
Output is correct |
11 |
Correct |
40 ms |
6040 KB |
Output is correct |
12 |
Correct |
128 ms |
6964 KB |
Output is correct |
13 |
Correct |
81 ms |
6568 KB |
Output is correct |
14 |
Correct |
127 ms |
6964 KB |
Output is correct |
15 |
Correct |
138 ms |
7228 KB |
Output is correct |
16 |
Correct |
59 ms |
6304 KB |
Output is correct |
17 |
Correct |
55 ms |
6304 KB |
Output is correct |
18 |
Correct |
87 ms |
6832 KB |
Output is correct |
19 |
Correct |
104 ms |
6832 KB |
Output is correct |
20 |
Correct |
48 ms |
6172 KB |
Output is correct |
21 |
Correct |
27 ms |
5908 KB |
Output is correct |
22 |
Correct |
31 ms |
8764 KB |
Output is correct |
23 |
Correct |
44 ms |
10096 KB |
Output is correct |
24 |
Correct |
44 ms |
10028 KB |
Output is correct |
25 |
Correct |
37 ms |
6964 KB |
Output is correct |
26 |
Correct |
68 ms |
8020 KB |
Output is correct |
27 |
Correct |
59 ms |
6964 KB |
Output is correct |
28 |
Correct |
33 ms |
6436 KB |
Output is correct |
29 |
Correct |
48 ms |
6832 KB |
Output is correct |
30 |
Correct |
53 ms |
6700 KB |
Output is correct |
31 |
Correct |
54 ms |
6700 KB |
Output is correct |
32 |
Correct |
29 ms |
5908 KB |
Output is correct |
33 |
Correct |
19 ms |
5900 KB |
Output is correct |
34 |
Correct |
21 ms |
5856 KB |
Output is correct |
35 |
Correct |
3 ms |
5512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5512 KB |
Output is correct |
2 |
Correct |
61 ms |
6224 KB |
Output is correct |
3 |
Correct |
59 ms |
6284 KB |
Output is correct |
4 |
Correct |
78 ms |
7096 KB |
Output is correct |
5 |
Correct |
88 ms |
8416 KB |
Output is correct |
6 |
Correct |
53 ms |
6964 KB |
Output is correct |
7 |
Correct |
80 ms |
13108 KB |
Output is correct |
8 |
Correct |
155 ms |
7228 KB |
Output is correct |
9 |
Correct |
57 ms |
6164 KB |
Output is correct |
10 |
Correct |
67 ms |
6284 KB |
Output is correct |
11 |
Correct |
79 ms |
7096 KB |
Output is correct |
12 |
Correct |
85 ms |
8416 KB |
Output is correct |
13 |
Correct |
48 ms |
6964 KB |
Output is correct |
14 |
Correct |
85 ms |
13112 KB |
Output is correct |
15 |
Correct |
139 ms |
7228 KB |
Output is correct |
16 |
Correct |
135 ms |
7228 KB |
Output is correct |
17 |
Correct |
141 ms |
7228 KB |
Output is correct |
18 |
Correct |
138 ms |
7096 KB |
Output is correct |
19 |
Correct |
106 ms |
6832 KB |
Output is correct |
20 |
Correct |
102 ms |
6700 KB |
Output is correct |
21 |
Correct |
103 ms |
6832 KB |
Output is correct |
22 |
Correct |
26 ms |
5908 KB |
Output is correct |
23 |
Correct |
87 ms |
6700 KB |
Output is correct |
24 |
Correct |
38 ms |
6040 KB |
Output is correct |
25 |
Correct |
49 ms |
6304 KB |
Output is correct |
26 |
Correct |
52 ms |
6304 KB |
Output is correct |
27 |
Correct |
110 ms |
6964 KB |
Output is correct |
28 |
Correct |
127 ms |
7096 KB |
Output is correct |
29 |
Correct |
123 ms |
7096 KB |
Output is correct |
30 |
Correct |
13 ms |
5644 KB |
Output is correct |
31 |
Correct |
26 ms |
5776 KB |
Output is correct |
32 |
Correct |
136 ms |
7096 KB |
Output is correct |
33 |
Correct |
120 ms |
6964 KB |
Output is correct |
34 |
Correct |
25 ms |
5908 KB |
Output is correct |
35 |
Correct |
129 ms |
7096 KB |
Output is correct |
36 |
Correct |
129 ms |
7096 KB |
Output is correct |
37 |
Correct |
103 ms |
6832 KB |
Output is correct |
38 |
Correct |
87 ms |
6700 KB |
Output is correct |
39 |
Correct |
137 ms |
7096 KB |
Output is correct |
40 |
Correct |
5 ms |
5644 KB |
Output is correct |
41 |
Correct |
45 ms |
6172 KB |
Output is correct |
42 |
Correct |
74 ms |
11788 KB |
Output is correct |
43 |
Correct |
34 ms |
8436 KB |
Output is correct |
44 |
Correct |
48 ms |
10188 KB |
Output is correct |
45 |
Correct |
70 ms |
8020 KB |
Output is correct |
46 |
Correct |
14 ms |
6172 KB |
Output is correct |
47 |
Correct |
61 ms |
10492 KB |
Output is correct |
48 |
Correct |
69 ms |
12016 KB |
Output is correct |
49 |
Correct |
82 ms |
12828 KB |
Output is correct |
50 |
Correct |
75 ms |
8152 KB |
Output is correct |
51 |
Correct |
42 ms |
6964 KB |
Output is correct |
52 |
Correct |
37 ms |
6568 KB |
Output is correct |
53 |
Correct |
48 ms |
6700 KB |
Output is correct |
54 |
Correct |
23 ms |
6172 KB |
Output is correct |
55 |
Correct |
55 ms |
6700 KB |
Output is correct |
56 |
Correct |
37 ms |
6304 KB |
Output is correct |
57 |
Correct |
119 ms |
7096 KB |
Output is correct |
58 |
Correct |
27 ms |
6172 KB |
Output is correct |
59 |
Correct |
29 ms |
6304 KB |
Output is correct |
60 |
Correct |
51 ms |
6832 KB |
Output is correct |
61 |
Correct |
24 ms |
6040 KB |
Output is correct |
62 |
Correct |
44 ms |
6436 KB |
Output is correct |
63 |
Correct |
57 ms |
6436 KB |
Output is correct |
64 |
Correct |
45 ms |
6284 KB |
Output is correct |
65 |
Correct |
56 ms |
6284 KB |
Output is correct |
66 |
Correct |
26 ms |
5848 KB |
Output is correct |
67 |
Correct |
28 ms |
5800 KB |
Output is correct |
68 |
Correct |
49 ms |
6024 KB |
Output is correct |
69 |
Correct |
22 ms |
5832 KB |
Output is correct |
70 |
Correct |
41 ms |
6092 KB |
Output is correct |
71 |
Correct |
24 ms |
5812 KB |
Output is correct |
72 |
Incorrect |
0 ms |
5512 KB |
Output isn't correct |