#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, k, h[100010], x, y, ans;
vector<int> g[100010];
int dfs(int no, int pa) {
int sum = h[no];
vector<int> v;
for(int i: g[no]) {
if(i == pa) continue;
v.push_back(dfs(i, no));
sum += v.back();
}
sort(v.begin(), v.end());
while(sum > k) {
sum -= v.back();
v.pop_back();
ans++;
}
return sum;
}
signed main() {
cin >> n >> k;
for(int i=1; i<=n; i++) {
cin >> h[i];
}
for(int i=1; i<n; i++) {
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1, -1);
cout << ans;
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... |