(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

제출 #43878

#제출 시각아이디문제언어결과실행 시간메모리
43878ngkan146Paprike (COI18_paprike)C++11
100 / 100
94 ms44348 KiB
#include <bits/stdc++.h> using namespace std; int n,cnt,val,w[100005]; vector <int> G[100005]; int dfs(int u,int p){ int res = w[u]; vector <int> child; for(int i=0;i<G[u].size();i++){ int v = G[u][i]; if (v == p) continue; child.push_back(dfs(v,u)); } sort(child.begin(),child.end()); int last = 0; for(last = 0;last < child.size();last ++) if (res + child[last] > val) break; else res += child[last]; cnt += child.size() - last; return res; } int solve(){ cnt = 0; dfs(1,1); return cnt; } int main(){ scanf("%d %d",&n,&val); for(int i=1;i<=n;i++) scanf("%d",&w[i]); for(int i=1;i<n;i++){ int x,y; scanf("%d %d",&x,&y); G[x].push_back(y); G[y].push_back(x); } printf("%d",solve()); }

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

paprike.cpp: In function 'int dfs(int, int)':
paprike.cpp:8:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<G[u].size();i++){
                 ~^~~~~~~~~~~~
paprike.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(last = 0;last < child.size();last ++)
                  ~~~~~^~~~~~~~~~~~~~
paprike.cpp: In function 'int main()':
paprike.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&val);
     ~~~~~^~~~~~~~~~~~~~~~~
paprike.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&w[i]);
         ~~~~~^~~~~~~~~~~~
paprike.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...