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;
int x,k,ans,a[100005];
vector<int>v[100005];
int dfs(int i,int p=-1){
vector<int>lol;
for(auto j:v[i]){
if(j==p)continue;
lol.push_back(dfs(j,i));
}
int ret=a[i];
sort(lol.begin(),lol.end());
for(auto j:lol)if(ret+j<=k)ret+=j;else ans++;
return ret;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>x>>k;
for(int i=1;i<=x;i++)cin>>a[i];
for(int i=1;i<=x-1;i++){
int l,r;cin>>l>>r;
v[l].push_back(r);
v[r].push_back(l);
}
dfs(1);
cout<<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... |