This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
vector <int> g[100010];
int h[100010];
long long sub[100010];
int k;
int ans;
void dfs(int x, int par) {
sub[x] = h[x];
vector <long long> v;
for(auto i : g[x]) {
if(i - par) {
dfs(i, x);
v.push_back(sub[i]);
}
}
sort(v.begin(), v.end());
for(auto i : v) {
if(sub[x] + i > k) {
++ans;
} else {
sub[x] += i;
}
}
}
int main(int argc, char const *argv[])
{
int n;
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> h[i];
for(int i = 1; i < n; i++) {
int p, q;
cin >> p >> q;
g[p].emplace_back(q);
g[q].emplace_back(p);
}
dfs(1, 0);
printf("%d\n", 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... |