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 mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
vector<int>adj[100005];
vector<int>val(100005,0);
int n,k;
int ans=0;
int dfs(int x,int pre){
int sum=val[x];
priority_queue<int,vector<int>,greater<int>>Q;
for(int i=0;i<adj[x].size();i++){
int y=adj[x][i];
if(y==pre)continue;
Q.push(dfs(y,x));
}
ans+=Q.size();
while(!Q.empty()&&sum+Q.top()<=k){
sum+=Q.top();
Q.pop();
ans--;
}
return sum;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("q.gir","r",stdin);
// freopen("q.cik","w",stdout);
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>val[i];
for(int i=0;i<n-1;i++){
int x,y;
cin>>x>>y;
adj[x].pb(y);
adj[y].pb(x);
}
dfs(1,0);
cout<<ans;
}
Compilation message (stderr)
paprike.cpp: In function 'long long int dfs(long long int, long long int)':
paprike.cpp:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<adj[x].size();i++){
~^~~~~~~~~~~~~~
# | 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... |