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;
typedef long long ll;
typedef long double ld;
typedef complex<long double> point;
const int maxn = 100000 + 10;
const int maxm = 50 + 5;
int k, cnt;
int a[maxn];
vector<int> t[maxn];
void dfs(int v, int par = -1){
cnt ++;
vector<int> A;
for (auto u : t[v])
if (u != par)
dfs(u, v), A.push_back(a[u]);
sort(A.begin(), A.end());
for (auto x : A)
if (a[v] + x <= k)
a[v] += x, cnt --;
}
int main(){
ios_base::sync_with_stdio(false);
int n;
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n-1; i++){
int v, u;
cin >> v >> u;
t[v].push_back(u);
t[u].push_back(v);
}
dfs(1);
cout << cnt - 1 << 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... |