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 ll = long long;
using namespace std;
const int mxN = 100005;
vector<int> aj[mxN];
ll a[mxN];
int cnt;
ll K;
ll dfs(int u, int p = 0) {
vector<ll> r;
ll sm = a[u];
for (int v : aj[u]) {
if (v ^ p) {
r.push_back(dfs(v, u));
}
}
sort(begin(r),end(r));
for (int i : r) {
if (sm + i <= K) {
sm += i;
} else {
cnt ++;
}
}
return sm;
}
int main() {
int N;
cin >> N >> K;
for (int i = 1; i <= N; i ++) {
cin >> a[i];
}
for (int i = 1; i <= N - 1; i ++) {
int X, Y;
cin >> X >> Y;
aj[X].push_back(Y);
aj[Y].push_back(X);
}
dfs(1, 0);
cout << cnt << endl;
}
# | 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... |