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

#TimeUsernameProblemLanguageResultExecution timeMemory
531071Alex_tz307Paprike (COI18_paprike)C++17
100 / 100
93 ms22208 KiB
#include <bits/stdc++.h> using namespace std; const int kN = 1e5; int n, k, h[1 + kN]; vector<int> g[1 + kN]; struct state { int minCuts; int64_t minSum; } dp[1 + kN]; void dfs(int u, int par) { dp[u].minCuts = 0; dp[u].minSum = h[u]; priority_queue<int64_t> pq; for (int v : g[u]) { if (v != par) { dfs(v, u); dp[u].minCuts += dp[v].minCuts; dp[u].minSum += dp[v].minSum; pq.emplace(dp[v].minSum); } } while (dp[u].minSum > k) { dp[u].minCuts += 1; dp[u].minSum -= pq.top(); pq.pop(); } } void testCase() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> h[i]; } for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; g[u].emplace_back(v); g[v].emplace_back(u); } dfs(1, 0); cout << dp[1].minCuts << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tests = 1; for (int tc = 0; tc < tests; ++tc) { testCase(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...