(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #676088

#TimeUsernameProblemLanguageResultExecution timeMemory
676088ToroTNPaprike (COI18_paprike)C++14
100 / 100
60 ms15952 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back int n,m,a[100005],u_i,v_i,sum[100005],cnt,total,ss,ans=0,w; vector<int> v[100005]; priority_queue<int> pq; void dfs(int u,int p) { for(auto node:v[u]) { if(node!=p)dfs(node,u); } if(v[u].size()==1&&u!=1) { sum[u]=a[u]; }else { if(u==1) { total=v[1].size(); }else { total=v[u].size()-1; } cnt=a[u]; for(auto node:v[u]) { if(node!=p) { pq.push(-sum[node]); } } ss=0; while(!pq.empty()) { w=-pq.top(); cnt+=w; pq.pop(); if(cnt>m) { cnt-=w; ss=pq.size()+1; break; } } while(!pq.empty())pq.pop(); sum[u]=cnt; ans+=ss; } } int main() { ios_base::sync_with_stdio(0),cin.tie(0); cin >> n >> m; for(int i=1;i<=n;i++)cin >> a[i]; for(int i=1;i<n;i++) { cin >> u_i >> v_i; v[u_i].pb(v_i); v[v_i].pb(u_i); } 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...