#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
vector<vector<int>> adj;
vector<long long> h;
long long k;
int total_cuts = 0;
long long dfs(int u, int p) {
long long current_wreath_spiciness = h[u];
for (int v : adj[u]) {
if (v == p) continue;
long long spiciness_from_child = dfs(v, u);
if (current_wreath_spiciness + spiciness_from_child <= k) current_wreath_spiciness += spiciness_from_child;
else total_cuts++;
}
return current_wreath_spiciness;
}
int main() {
int n;
cin >> n >> k;
h.resize(n + 1);
adj.resize(n + 1);
for (int i = 1; i <= n; ++i) cin >> h[i];
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
cout << total_cuts << endl;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |