Submission #1043902

#TimeUsernameProblemLanguageResultExecution timeMemory
1043902vjudge1Paprike (COI18_paprike)C++17
100 / 100
77 ms18512 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int M = 1e5 + 1; vector<int> nei[M]; int cts[M],sps[M],k; void dfs(int u,int p=0) { vector<int> v; for (int i:nei[u]) if (i!=p) { dfs(i,u); cts[u]+=cts[i]; sps[u]+=sps[i]; v.push_back(sps[i]); } sort(v.begin(),v.end()); while (sps[u]>k) { sps[u]-=v.back(); v.pop_back(); cts[u]++; } } signed main() { int n; cin>>n>>k; for (int i=1;i<=n;i++) cin>>sps[i]; for (int i=1;i<n;i++) { int u,v; cin>>u>>v; nei[u].push_back(v); nei[v].push_back(u); } dfs(1); cout<<cts[1]<<endl; 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...