Submission #864308

#TimeUsernameProblemLanguageResultExecution timeMemory
864308serifefedartarPaprike (COI18_paprike)C++17
100 / 100
47 ms19628 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); #define s second #define f first typedef long long ll; const ll MOD = 1e9 + 7; const ll LOGN = 20; const ll MAXN = 1e5 + 100; vector<vector<int>> graph; ll h[MAXN]; int k, ans = 0; int dfs(int node, int parent) { vector<int> v; for (auto u : graph[node]) { if (u == parent) continue; v.push_back(dfs(u, node)); if (v.back() == 0) v.pop_back(); } int rem = k - h[node]; sort(v.begin(), v.end(), greater<int>()); while (v.size()) { if (v.back() <= rem) { rem -= v.back(); v.pop_back(); } else break; } ans += v.size(); return (k - rem); } int main() { fast int n, a, b; cin >> n >> k; graph = vector<vector<int>>(n+1, vector<int>()); for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i < n; i++) { cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } dfs(1, 1); cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...