Submission #13854

# Submission time Handle Problem Language Result Execution time Memory
13854 2015-04-08T00:49:16 Z gs14004 Company Planning (TOKI14_company) C++14
Compilation error
0 ms 0 KB
#include <cstdio>
#include <vector>
using namespace std;

vector<int> graph[100005];
int n,m;
int lim;

int solve(int x){
    vector<int> ret;
    for (int i=0; i<graph[x].size(); i++) {
        ret.push_back(solve(graph[x][i]));
    }
    sort(ret.begin(),ret.end());
    reverse(ret.begin(),ret.end());
    int res = 0;
    for (int i=0; i<lim && i < ret.size(); i++) {
        res += ret[i];
    }
    return res + 1;
}

bool trial(int x){
    lim = x;
    return solve(1) >= m;
}

int main(){
    scanf("%d %d",&n,&m);
    for (int i=2; i<=n; i++) {
        int t;
        scanf("%d",&t);
        graph[t].push_back(i);
    }
    int s = 0, e = n;
    while (s != e) {
        int m = (s+e)/2;
        if(trial(m)) e = m;
        else s = m+1;
    }
    printf("%d",s);
}

Compilation message

company.cpp: In function ‘int solve(int)’:
company.cpp:11:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<graph[x].size(); i++) {
                    ^
company.cpp:14:31: error: ‘sort’ was not declared in this scope
     sort(ret.begin(),ret.end());
                               ^
company.cpp:15:34: error: ‘reverse’ was not declared in this scope
     reverse(ret.begin(),ret.end());
                                  ^
company.cpp:17:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<lim && i < ret.size(); i++) {
                              ^
company.cpp: In function ‘int main()’:
company.cpp:29:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
                         ^
company.cpp:32:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&t);
                       ^