(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 #233094

#TimeUsernameProblemLanguageResultExecution timeMemory
233094PeppaPigPaprike (COI18_paprike)C++14
100 / 100
96 ms17656 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5+5; int n, k, ans, A[N]; vector<int> g[N]; int dfs(int u, int p) { int sum = A[u]; vector<int> vec; for(int v : g[u]) if(v != p) vec.emplace_back(dfs(v, u)); sort(vec.begin(), vec.end()); for(int i = 0; i < vec.size(); i++) { if(sum + vec[i] > k) ++ans; else sum += vec[i]; } return sum; } int main() { scanf("%d %d", &n, &k); for(int i = 1; i <= n; i++) scanf("%d", A + i); for(int i = 1, a, b; i < n; i++) { scanf("%d %d", &a, &b); g[a].emplace_back(b); g[b].emplace_back(a); } dfs(1, 0); printf("%d\n", ans); return 0; }

Compilation message (stderr)

paprike.cpp: In function 'int dfs(int, int)':
paprike.cpp:16:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < vec.size(); i++) {
                    ~~^~~~~~~~~~~~
paprike.cpp: In function 'int main()':
paprike.cpp:24: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:25:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%d", A + i);
                                 ~~~~~^~~~~~~~~~~~~
paprike.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &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...