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

#TimeUsernameProblemLanguageResultExecution timeMemory
296474BeanZPaprike (COI18_paprike)C++14
100 / 100
81 ms18044 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 1e5 + 5; ll dp[N], cur[N], a[N]; ll k; vector<ll> node[N]; void dfs(ll u, ll p){ vector<ll> v; cur[u] = a[u]; for (auto j : node[u]){ if (j == p) continue; dfs(j, u); v.push_back(cur[j]); dp[u] = dp[u] + dp[j]; } sort(v.begin(), v.end()); for (int i = 0; i < (ll)v.size(); i++){ if ((cur[u] + v[i]) > k){ dp[u] = dp[u] + v.size() - i; break; } cur[u] += v[i]; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("balance.in", "r")){ freopen("balance.in", "r", stdin); freopen("balance.out", "w", stdout); } ll n; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i < n; i++){ ll u, v; cin >> u >> v; node[u].push_back(v); node[v].push_back(u); } dfs(1, 1); cout << dp[1]; } /* */

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:33:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   33 |                 freopen("balance.in", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
paprike.cpp:34:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |                 freopen("balance.out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...