제출 #748277

#제출 시각아이디문제언어결과실행 시간메모리
748277Username4132Paprike (COI18_paprike)C++14
13 / 100
52 ms15584 KiB
#include<iostream> #include<vector> #include<algorithm> using namespace std; #define forn(i, n) for(int i=0; i<(int)n; ++i) #define PB push_back const int MAXN=100010; int n, k, ans, arr[MAXN], par[MAXN], dep[MAXN], order[MAXN]; vector<int> g[MAXN]; void dfs(int v, int p){ par[v]=p; for(int to:g[v]) if(to!=p) { dep[to]=dep[v]+1; dfs(to, v); } } int main(){ scanf("%d %d", &n, &k); forn(i, n) scanf("%d", &arr[i]), order[i]=i; forn(i, n-1){ int a, b; scanf("%d %d", &a, &b); --a, --b; g[a].PB(b), g[b].PB(a); } dfs(0, 0); sort(order, order+n, [](int a, int b){ return dep[a]!=dep[b]? dep[a]>dep[b] : arr[a]<arr[b]; }); forn(i, n-1){ int ind=order[i]; if(arr[ind]+arr[par[ind]]<=k) arr[par[ind]]+=arr[ind]; else ans++; } printf("%d\n", ans); }

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

paprike.cpp: In function 'int main()':
paprike.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
paprike.cpp:22:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     forn(i, n) scanf("%d", &arr[i]), order[i]=i;
      |                ~~~~~^~~~~~~~~~~~~~~
paprike.cpp:24:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         int a, b; scanf("%d %d", &a, &b); --a, --b;
      |                   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...