#include <bits/stdc++.h>
#define ll long long
#define vec vector
#define pb push_back
#define pll array<ll, 2>
#define all(X) X.begin(), X.end()
#define allr(X) X.rbegin(), X.rend()
using namespace std;
const ll inf = 1e18;
ll res = 0, k;
vec<vec<ll>>g;
vec<ll>sp;
void dfs(ll u, ll p){
multiset<ll>st;
for(ll &v : g[u]){
if(v != p){
dfs(v, u);
st.insert(v);
}
}
ll add = st.size();
for(ll v : st){
if(sp[v] <= k - sp[u]) sp[u] += sp[v], add--;
else break;
} res += add;
}
void _(){
ll n; cin >> n >> k;
g.assign(n + 1, {}); sp.resize(n);
for(ll &i : sp) cin >> i;
while(n--){
ll a, b; cin >> a >> b;
g[a].pb(b), g[b].pb(a);
}
dfs(1, 1);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(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... |