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;
const int maxn=100000+10;
vector<int>adj[maxn];
int val[maxn];
int n,k;
int res=0;
int solve(int u=1,int par=-1){
vector<int>v;
for(auto x:adj[u]){
if(x!=par){
v.push_back(solve(x,u));
}
}
sort(v.begin(),v.end());
int suma=val[u];
for(int i=0;i<(int)v.size();i++){
if(suma+v[i]<=k){
suma+=v[i];
continue;
}
else{
res++;
}
}
return suma;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>val[i];
}
for(int i=1;i<=n-1;i++){
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
solve();
cout<<res<<"\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... |