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>
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define ll long long
#define int ll
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define all(n) (n).begin(),(n).end()
using namespace std;
ll val[100005];
vector<int> E[100005];
ll res[100005];
int ans = 0;
ll n,k;
void dfs(int x,int p){
res[x] = val[x];
vector<ll> tmp;
for(auto i:E[x]){
if(i==p)continue;
dfs(i,x);
tmp.pb(res[i]);
}
sort(all(tmp));
for(auto i:tmp){
if(res[x]+i>k)ans++;
else res[x]+=i;
}
}
signed main(){
IOS;
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>val[i];
}
for(int i=1,a,b;i<n;i++){
cin>>a>>b;
E[a].pb(b);
E[b].pb(a);
}
dfs(1,0);
cout<<ans<<'\n';
}
# | 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... |