Submission #640581

#TimeUsernameProblemLanguageResultExecution timeMemory
640581anhduc2701Paprike (COI18_paprike)C++17
24 / 100
133 ms22192 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll INF=1e18; const int maxn=1e6+5; const int mod=1e9+7; using pi=pair<ll,ll>; using vi=vector<ll>; using pii=pair<pair<ll,ll>,ll>; #define all(x) x.begin(), x.end() #define len(x) ll(x.size()) #define eb emplace_back #define fi first #define se second #define mp make_pair #define pb push_back #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) int dp[100005]; vector<int>G[100005]; int ans=0; int n; int a[100005]; int root; int k; priority_queue<int>pq[100005]; int dfs(int u,int p){ dp[u]=a[u]; for(auto v:G[u]){ if(v==p)continue; int d=dfs(v,u); pq[u].push(d); dp[u]+=d; if(dp[u]>k){ dp[u]-=pq[u].top(); pq[u].top(); ans++; } } return dp[u]; } signed main(){ cin>>n>>k; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n-1;i++){ int x,y; cin>>x>>y; G[x].push_back(y); G[y].push_back(x); } dfs(1,1); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...