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

#TimeUsernameProblemLanguageResultExecution timeMemory
603351ZanitePaprike (COI18_paprike)C++17
100 / 100
62 ms19848 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; using pll = pair<ll, ll>; #define fi first #define se second const int maxN = 1e5 + 5; int n; ll k, h[maxN], sum[maxN]; vector<int> adj[maxN]; int dfs(int cur, int par) { int ret = 0; sum[cur] = h[cur]; vector<int> spice; for (auto &nxt : adj[cur]) { if (nxt == par) continue; ret += dfs(nxt, cur); spice.push_back(sum[nxt]); } sort(spice.begin(), spice.end()); for (int i = 0; i < spice.size(); i++) { if (sum[cur] + spice[i] > k) ret++; else sum[cur] += spice[i]; } return ret; } int main() { scanf("%d %lld", &n, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &h[i]); } for (int u, v, i = 1; i < n; i++) { scanf("%d %d", &u, &v); adj[u].push_back(v); adj[v].push_back(u); } printf("%d\n", dfs(1, 0)); }

Compilation message (stderr)

paprike.cpp: In function 'int dfs(int, int)':
paprike.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for (int i = 0; i < spice.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
paprike.cpp: In function 'int main()':
paprike.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d %lld", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
paprike.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%lld", &h[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
paprike.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...