Submission #14253

# Submission time Handle Problem Language Result Execution time Memory
14253 2015-05-07T15:22:57 Z dohyun0324 Company Planning (TOKI14_company) C++
100 / 100
161 ms 13112 KB
#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==1){printf("0"); return 0;}
    init(1);
    bsearch();
    return 0;
}
# Verdict Execution time Memory 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 Correct 0 ms 5512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5512 KB Output is correct
2 Correct 2 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 1 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 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 2 ms 5512 KB Output is correct
16 Correct 2 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 0 ms 5512 KB Output is correct
31 Correct 0 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 Correct 0 ms 5512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5512 KB Output is correct
2 Correct 155 ms 7492 KB Output is correct
3 Correct 59 ms 6964 KB Output is correct
4 Correct 58 ms 6964 KB Output is correct
5 Correct 155 ms 7492 KB Output is correct
6 Correct 139 ms 7228 KB Output is correct
7 Correct 134 ms 7228 KB Output is correct
8 Correct 130 ms 7096 KB Output is correct
9 Correct 133 ms 7228 KB Output is correct
10 Correct 106 ms 6964 KB Output is correct
11 Correct 126 ms 7096 KB Output is correct
12 Correct 150 ms 7360 KB Output is correct
13 Correct 143 ms 7360 KB Output is correct
14 Correct 80 ms 6700 KB Output is correct
15 Correct 145 ms 7360 KB Output is correct
16 Correct 77 ms 6700 KB Output is correct
17 Correct 113 ms 7096 KB Output is correct
18 Correct 58 ms 6436 KB Output is correct
19 Correct 22 ms 6040 KB Output is correct
20 Correct 49 ms 6700 KB Output is correct
21 Correct 30 ms 6436 KB Output is correct
22 Correct 10 ms 5908 KB Output is correct
23 Correct 42 ms 6700 KB Output is correct
24 Correct 51 ms 6832 KB Output is correct
25 Correct 1 ms 5512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5512 KB Output is correct
2 Correct 59 ms 6088 KB Output is correct
3 Correct 55 ms 6284 KB Output is correct
4 Correct 76 ms 7096 KB Output is correct
5 Correct 89 ms 8416 KB Output is correct
6 Correct 55 ms 6964 KB Output is correct
7 Correct 85 ms 13112 KB Output is correct
8 Correct 144 ms 7228 KB Output is correct
9 Correct 139 ms 7228 KB Output is correct
10 Correct 114 ms 6832 KB Output is correct
11 Correct 34 ms 6040 KB Output is correct
12 Correct 113 ms 6964 KB Output is correct
13 Correct 87 ms 6568 KB Output is correct
14 Correct 122 ms 6964 KB Output is correct
15 Correct 161 ms 7228 KB Output is correct
16 Correct 66 ms 6304 KB Output is correct
17 Correct 62 ms 6304 KB Output is correct
18 Correct 87 ms 6832 KB Output is correct
19 Correct 114 ms 6832 KB Output is correct
20 Correct 51 ms 6172 KB Output is correct
21 Correct 25 ms 5908 KB Output is correct
22 Correct 30 ms 8764 KB Output is correct
23 Correct 48 ms 10092 KB Output is correct
24 Correct 47 ms 10032 KB Output is correct
25 Correct 41 ms 6964 KB Output is correct
26 Correct 64 ms 8020 KB Output is correct
27 Correct 43 ms 6964 KB Output is correct
28 Correct 33 ms 6436 KB Output is correct
29 Correct 50 ms 6832 KB Output is correct
30 Correct 60 ms 6700 KB Output is correct
31 Correct 44 ms 6700 KB Output is correct
32 Correct 29 ms 5908 KB Output is correct
33 Correct 25 ms 5900 KB Output is correct
34 Correct 26 ms 5856 KB Output is correct
35 Correct 6 ms 5512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5512 KB Output is correct
2 Correct 58 ms 6224 KB Output is correct
3 Correct 60 ms 6284 KB Output is correct
4 Correct 72 ms 7096 KB Output is correct
5 Correct 79 ms 8416 KB Output is correct
6 Correct 52 ms 6964 KB Output is correct
7 Correct 82 ms 13112 KB Output is correct
8 Correct 151 ms 7228 KB Output is correct
9 Correct 56 ms 6164 KB Output is correct
10 Correct 59 ms 6284 KB Output is correct
11 Correct 75 ms 7096 KB Output is correct
12 Correct 81 ms 8416 KB Output is correct
13 Correct 61 ms 6964 KB Output is correct
14 Correct 85 ms 13112 KB Output is correct
15 Correct 149 ms 7228 KB Output is correct
16 Correct 136 ms 7228 KB Output is correct
17 Correct 140 ms 7228 KB Output is correct
18 Correct 134 ms 7096 KB Output is correct
19 Correct 112 ms 6832 KB Output is correct
20 Correct 98 ms 6700 KB Output is correct
21 Correct 110 ms 6832 KB Output is correct
22 Correct 26 ms 5908 KB Output is correct
23 Correct 89 ms 6700 KB Output is correct
24 Correct 39 ms 6040 KB Output is correct
25 Correct 51 ms 6304 KB Output is correct
26 Correct 54 ms 6304 KB Output is correct
27 Correct 108 ms 6964 KB Output is correct
28 Correct 110 ms 7096 KB Output is correct
29 Correct 130 ms 7096 KB Output is correct
30 Correct 13 ms 5644 KB Output is correct
31 Correct 21 ms 5776 KB Output is correct
32 Correct 134 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 133 ms 7096 KB Output is correct
37 Correct 99 ms 6832 KB Output is correct
38 Correct 87 ms 6700 KB Output is correct
39 Correct 140 ms 7096 KB Output is correct
40 Correct 7 ms 5644 KB Output is correct
41 Correct 50 ms 6172 KB Output is correct
42 Correct 57 ms 11792 KB Output is correct
43 Correct 30 ms 8432 KB Output is correct
44 Correct 44 ms 10188 KB Output is correct
45 Correct 66 ms 8020 KB Output is correct
46 Correct 12 ms 6172 KB Output is correct
47 Correct 61 ms 10496 KB Output is correct
48 Correct 75 ms 12016 KB Output is correct
49 Correct 85 ms 12828 KB Output is correct
50 Correct 76 ms 8152 KB Output is correct
51 Correct 44 ms 6964 KB Output is correct
52 Correct 40 ms 6568 KB Output is correct
53 Correct 45 ms 6700 KB Output is correct
54 Correct 24 ms 6172 KB Output is correct
55 Correct 48 ms 6700 KB Output is correct
56 Correct 33 ms 6304 KB Output is correct
57 Correct 108 ms 7096 KB Output is correct
58 Correct 26 ms 6172 KB Output is correct
59 Correct 31 ms 6304 KB Output is correct
60 Correct 44 ms 6832 KB Output is correct
61 Correct 25 ms 6040 KB Output is correct
62 Correct 33 ms 6436 KB Output is correct
63 Correct 61 ms 6436 KB Output is correct
64 Correct 51 ms 6284 KB Output is correct
65 Correct 54 ms 6284 KB Output is correct
66 Correct 31 ms 5848 KB Output is correct
67 Correct 27 ms 5800 KB Output is correct
68 Correct 48 ms 6024 KB Output is correct
69 Correct 22 ms 5832 KB Output is correct
70 Correct 45 ms 6092 KB Output is correct
71 Correct 28 ms 5812 KB Output is correct
72 Correct 0 ms 5512 KB Output is correct