Submission #14251

# Submission time Handle Problem Language Result Execution time Memory
14251 2015-05-07T15:15:55 Z dohyun0324 Company Planning (TOKI14_company) C++
7 / 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){printf("0"); return 0;}
    init(1);
    bsearch();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 2 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 1 ms 5512 KB Output isn't correct
# 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 2 ms 5512 KB Output is correct
5 Correct 0 ms 5512 KB Output is correct
6 Correct 2 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 1 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 2 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 1 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 2 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5512 KB Output is correct
2 Correct 157 ms 7492 KB Output is correct
3 Correct 57 ms 6964 KB Output is correct
4 Correct 64 ms 6964 KB Output is correct
5 Correct 153 ms 7492 KB Output is correct
6 Correct 140 ms 7228 KB Output is correct
7 Correct 134 ms 7228 KB Output is correct
8 Correct 133 ms 7096 KB Output is correct
9 Correct 139 ms 7228 KB Output is correct
10 Correct 105 ms 6964 KB Output is correct
11 Correct 131 ms 7096 KB Output is correct
12 Correct 152 ms 7360 KB Output is correct
13 Correct 161 ms 7360 KB Output is correct
14 Correct 78 ms 6700 KB Output is correct
15 Correct 139 ms 7360 KB Output is correct
16 Correct 76 ms 6700 KB Output is correct
17 Correct 122 ms 7096 KB Output is correct
18 Correct 60 ms 6436 KB Output is correct
19 Correct 23 ms 6040 KB Output is correct
20 Correct 44 ms 6700 KB Output is correct
21 Correct 34 ms 6436 KB Output is correct
22 Correct 14 ms 5908 KB Output is correct
23 Correct 49 ms 6700 KB Output is correct
24 Correct 54 ms 6832 KB Output is correct
25 Incorrect 0 ms 5512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5512 KB Output is correct
2 Correct 61 ms 6088 KB Output is correct
3 Correct 56 ms 6284 KB Output is correct
4 Correct 68 ms 7096 KB Output is correct
5 Correct 77 ms 8416 KB Output is correct
6 Correct 59 ms 6964 KB Output is correct
7 Correct 83 ms 13108 KB Output is correct
8 Correct 152 ms 7228 KB Output is correct
9 Correct 144 ms 7228 KB Output is correct
10 Correct 112 ms 6832 KB Output is correct
11 Correct 39 ms 6040 KB Output is correct
12 Correct 118 ms 6964 KB Output is correct
13 Correct 88 ms 6568 KB Output is correct
14 Correct 125 ms 6964 KB Output is correct
15 Correct 148 ms 7228 KB Output is correct
16 Correct 62 ms 6304 KB Output is correct
17 Correct 59 ms 6304 KB Output is correct
18 Correct 101 ms 6832 KB Output is correct
19 Correct 98 ms 6832 KB Output is correct
20 Correct 49 ms 6172 KB Output is correct
21 Correct 25 ms 5908 KB Output is correct
22 Correct 31 ms 8768 KB Output is correct
23 Correct 41 ms 10092 KB Output is correct
24 Correct 42 ms 10032 KB Output is correct
25 Correct 35 ms 6964 KB Output is correct
26 Correct 72 ms 8020 KB Output is correct
27 Correct 41 ms 6964 KB Output is correct
28 Correct 30 ms 6436 KB Output is correct
29 Correct 51 ms 6832 KB Output is correct
30 Correct 54 ms 6700 KB Output is correct
31 Correct 57 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 29 ms 5856 KB Output is correct
35 Correct 3 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 57 ms 6284 KB Output is correct
4 Correct 78 ms 7096 KB Output is correct
5 Correct 85 ms 8416 KB Output is correct
6 Correct 60 ms 6964 KB Output is correct
7 Correct 81 ms 13112 KB Output is correct
8 Correct 158 ms 7228 KB Output is correct
9 Correct 56 ms 6164 KB Output is correct
10 Correct 58 ms 6284 KB Output is correct
11 Correct 83 ms 7096 KB Output is correct
12 Correct 85 ms 8416 KB Output is correct
13 Correct 50 ms 6964 KB Output is correct
14 Correct 92 ms 13112 KB Output is correct
15 Correct 146 ms 7228 KB Output is correct
16 Correct 140 ms 7228 KB Output is correct
17 Correct 146 ms 7228 KB Output is correct
18 Correct 144 ms 7096 KB Output is correct
19 Correct 115 ms 6832 KB Output is correct
20 Correct 93 ms 6700 KB Output is correct
21 Correct 111 ms 6832 KB Output is correct
22 Correct 31 ms 5908 KB Output is correct
23 Correct 94 ms 6700 KB Output is correct
24 Correct 36 ms 6040 KB Output is correct
25 Correct 51 ms 6304 KB Output is correct
26 Correct 52 ms 6304 KB Output is correct
27 Correct 115 ms 6964 KB Output is correct
28 Correct 123 ms 7096 KB Output is correct
29 Correct 129 ms 7096 KB Output is correct
30 Correct 13 ms 5644 KB Output is correct
31 Correct 27 ms 5776 KB Output is correct
32 Correct 135 ms 7096 KB Output is correct
33 Correct 114 ms 6964 KB Output is correct
34 Correct 25 ms 5908 KB Output is correct
35 Correct 121 ms 7096 KB Output is correct
36 Correct 134 ms 7096 KB Output is correct
37 Correct 104 ms 6832 KB Output is correct
38 Correct 80 ms 6700 KB Output is correct
39 Correct 143 ms 7096 KB Output is correct
40 Correct 8 ms 5644 KB Output is correct
41 Correct 54 ms 6172 KB Output is correct
42 Correct 71 ms 11792 KB Output is correct
43 Correct 34 ms 8432 KB Output is correct
44 Correct 49 ms 10184 KB Output is correct
45 Correct 73 ms 8020 KB Output is correct
46 Correct 15 ms 6172 KB Output is correct
47 Correct 55 ms 10492 KB Output is correct
48 Correct 69 ms 12016 KB Output is correct
49 Correct 90 ms 12828 KB Output is correct
50 Correct 65 ms 8152 KB Output is correct
51 Correct 35 ms 6964 KB Output is correct
52 Correct 44 ms 6568 KB Output is correct
53 Correct 38 ms 6700 KB Output is correct
54 Correct 25 ms 6172 KB Output is correct
55 Correct 45 ms 6700 KB Output is correct
56 Correct 38 ms 6304 KB Output is correct
57 Correct 114 ms 7096 KB Output is correct
58 Correct 25 ms 6172 KB Output is correct
59 Correct 23 ms 6304 KB Output is correct
60 Correct 46 ms 6832 KB Output is correct
61 Correct 27 ms 6040 KB Output is correct
62 Correct 44 ms 6436 KB Output is correct
63 Correct 55 ms 6436 KB Output is correct
64 Correct 47 ms 6284 KB Output is correct
65 Correct 54 ms 6284 KB Output is correct
66 Correct 33 ms 5848 KB Output is correct
67 Correct 28 ms 5800 KB Output is correct
68 Correct 45 ms 6024 KB Output is correct
69 Correct 23 ms 5832 KB Output is correct
70 Correct 45 ms 6092 KB Output is correct
71 Correct 27 ms 5812 KB Output is correct
72 Incorrect 0 ms 5512 KB Output isn't correct