(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 #1117762

#TimeUsernameProblemLanguageResultExecution timeMemory
1117762vjudge1Paprike (COI18_paprike)C++17
100 / 100
43 ms19984 KiB
#include<bits/stdc++.h> using namespace std; vector<int>g[100001]; long long dp[100001],val[100001]; long long k; int ans; void dfs(int n,int p) { dp[n]=val[n]; vector<int>v; for(int g:g[n]) { if(g!=p) { dfs(g,n); dp[n]+=dp[g]; v.push_back(dp[g]); } } sort(v.begin(),v.end()); reverse(v.begin(),v.end()); int ind=0; while(dp[n]>k) { ans++; dp[n]-=v[ind]; ind++; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n>>k; for(int i=1;i<=n;i++) cin>>val[i]; for(int i=0;i<n-1;i++) { int a,b; cin>>a>>b; g[a].push_back(b); g[b].push_back(a); } dfs(1,0); cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...