Submission #1043895

#TimeUsernameProblemLanguageResultExecution timeMemory
1043895vjudge1Paprike (COI18_paprike)C++17
13 / 100
80 ms17600 KiB
#include <bits/stdc++.h> using namespace std; 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(); cts[u]++; } } int 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...