제출 #13854

#제출 시각아이디문제언어결과실행 시간메모리
13854gs14004Company Planning (TOKI14_company)C++14
컴파일 에러
0 ms0 KiB
#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); }

컴파일 시 표준 에러 (stderr) 메시지

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);
                       ^