#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>con[100010];
int 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]];
}
b=con[x].size();
maxi=max(maxi,b);
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);
}
init(1);
// bsearch();
printf("%d",maxi);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5116 KB |
Output is correct |
2 |
Incorrect |
1 ms |
5116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5116 KB |
Output is correct |
2 |
Incorrect |
0 ms |
5116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5116 KB |
Output is correct |
2 |
Correct |
28 ms |
7096 KB |
Output is correct |
3 |
Correct |
28 ms |
6568 KB |
Output is correct |
4 |
Correct |
0 ms |
6568 KB |
Output is correct |
5 |
Correct |
24 ms |
7096 KB |
Output is correct |
6 |
Correct |
32 ms |
6832 KB |
Output is correct |
7 |
Correct |
31 ms |
6832 KB |
Output is correct |
8 |
Correct |
26 ms |
6700 KB |
Output is correct |
9 |
Correct |
22 ms |
6832 KB |
Output is correct |
10 |
Correct |
14 ms |
6568 KB |
Output is correct |
11 |
Correct |
29 ms |
6700 KB |
Output is correct |
12 |
Correct |
35 ms |
6964 KB |
Output is correct |
13 |
Correct |
23 ms |
6964 KB |
Output is correct |
14 |
Correct |
11 ms |
6304 KB |
Output is correct |
15 |
Correct |
12 ms |
6964 KB |
Output is correct |
16 |
Correct |
23 ms |
6304 KB |
Output is correct |
17 |
Correct |
14 ms |
6700 KB |
Output is correct |
18 |
Correct |
13 ms |
6040 KB |
Output is correct |
19 |
Correct |
9 ms |
5644 KB |
Output is correct |
20 |
Correct |
22 ms |
6304 KB |
Output is correct |
21 |
Correct |
16 ms |
6040 KB |
Output is correct |
22 |
Correct |
5 ms |
5512 KB |
Output is correct |
23 |
Correct |
21 ms |
6304 KB |
Output is correct |
24 |
Correct |
19 ms |
6436 KB |
Output is correct |
25 |
Incorrect |
0 ms |
5116 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5116 KB |
Output is correct |
2 |
Correct |
13 ms |
5692 KB |
Output is correct |
3 |
Correct |
12 ms |
5888 KB |
Output is correct |
4 |
Correct |
23 ms |
6700 KB |
Output is correct |
5 |
Correct |
28 ms |
8020 KB |
Output is correct |
6 |
Correct |
27 ms |
6568 KB |
Output is correct |
7 |
Correct |
26 ms |
11152 KB |
Output is correct |
8 |
Correct |
17 ms |
6832 KB |
Output is correct |
9 |
Correct |
17 ms |
6832 KB |
Output is correct |
10 |
Correct |
28 ms |
6436 KB |
Output is correct |
11 |
Correct |
8 ms |
5644 KB |
Output is correct |
12 |
Correct |
18 ms |
6568 KB |
Output is correct |
13 |
Correct |
21 ms |
6172 KB |
Output is correct |
14 |
Correct |
23 ms |
6568 KB |
Output is correct |
15 |
Correct |
27 ms |
6832 KB |
Output is correct |
16 |
Correct |
5 ms |
5908 KB |
Output is correct |
17 |
Correct |
17 ms |
5908 KB |
Output is correct |
18 |
Correct |
26 ms |
6436 KB |
Output is correct |
19 |
Correct |
14 ms |
6436 KB |
Output is correct |
20 |
Correct |
15 ms |
5776 KB |
Output is correct |
21 |
Correct |
0 ms |
5512 KB |
Output is correct |
22 |
Correct |
0 ms |
7680 KB |
Output is correct |
23 |
Correct |
14 ms |
8744 KB |
Output is correct |
24 |
Correct |
9 ms |
8708 KB |
Output is correct |
25 |
Correct |
9 ms |
6568 KB |
Output is correct |
26 |
Correct |
0 ms |
7624 KB |
Output is correct |
27 |
Correct |
27 ms |
6568 KB |
Output is correct |
28 |
Correct |
8 ms |
6040 KB |
Output is correct |
29 |
Correct |
18 ms |
6436 KB |
Output is correct |
30 |
Correct |
15 ms |
6304 KB |
Output is correct |
31 |
Correct |
23 ms |
6304 KB |
Output is correct |
32 |
Correct |
9 ms |
5512 KB |
Output is correct |
33 |
Correct |
6 ms |
5504 KB |
Output is correct |
34 |
Correct |
7 ms |
5460 KB |
Output is correct |
35 |
Correct |
0 ms |
5116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5116 KB |
Output is correct |
2 |
Incorrect |
12 ms |
5828 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |