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

#TimeUsernameProblemLanguageResultExecution timeMemory
586376MilosMilutinovicPaprike (COI18_paprike)C++14
100 / 100
57 ms19480 KiB
/** * author: wxhtzdy * created: 30.06.2022 09:53:47 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<vector<int>> g(n); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; --u; --v; g[u].push_back(v); g[v].push_back(u); } int ans = 0; vector<long long> f(n); function<void(int, int)> Dfs = [&](int v, int pr) { vector<int> ch; for (int u : g[v]) { if (u == pr) { continue; } Dfs(u, v); ch.push_back(u); } sort(ch.begin(), ch.end(), [&](int i, int j) { return f[i] < f[j]; }); f[v] = a[v]; for (int i = 0; i < (int) ch.size(); i++) { if (f[v] + f[ch[i]] <= k) { f[v] += f[ch[i]]; } else { ans += 1; } } }; Dfs(0, 0); cout << ans << '\n'; 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...