(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.

Submission #201843

#TimeUsernameProblemLanguageResultExecution timeMemory
201843anonymousPaprike (COI18_paprike)C++14
100 / 100
83 ms16376 KiB
#include<iostream> #include<vector> #include<algorithm> #define MAXN 100005 using namespace std; int N,K,wt[MAXN]; int ui,vi,ans, S[MAXN]; vector <int> adj[MAXN],Val; int dfs(int u, int prev) { for (auto v: adj[u]) { if (v != prev) {dfs(v,u);} } for (auto v: adj[u]) { if (v != prev) {Val.push_back(S[v]);} } sort(Val.begin(), Val.end()); S[u]=wt[u]; for (auto w: Val) { if (S[u]+w<=K) {S[u]+=w;} else {ans++;} } Val.clear(); } int main() { //freopen("paprikein.txt","r",stdin); scanf("%d %d",&N,&K); for (int i=1; i<=N; i++) { scanf("%d",&wt[i]); } for (int i=1; i<N; i++) { scanf("%d %d",&ui,&vi); adj[ui].push_back(vi); adj[vi].push_back(ui); } dfs(1,0); printf("%d\n", ans); }

Compilation message (stderr)

paprike.cpp: In function 'int dfs(int, int)':
paprike.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
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,&K);
     ~~~~~^~~~~~~~~~~~~~~
paprike.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&wt[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",&ui,&vi);
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...