제출 #1043899

#제출 시각아이디문제언어결과실행 시간메모리
1043899vjudge1Paprike (COI18_paprike)C++17
0 / 100
1086 ms17772 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; int a[n]; for (int i=1;i<=n;i++) cin>>a[i]; for (int i=1;i<n;i++) { int u,v; cin>>u>>v; nei[u].push_back(v); nei[v].push_back(u); } int ans=n-1; for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) sps[j]=a[j],cts[j]=0; dfs(i); ans=min(ans,cts[i]); } cout<<ans<<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...