제출 #1117587

#제출 시각아이디문제언어결과실행 시간메모리
1117587vjudge1Paprike (COI18_paprike)C++17
100 / 100
98 ms26220 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long ll n, k, a, b; vector<ll> sp, dp; vector<vector<int>> v; int cnt = 0; void dfs(int x, int p){ set<vector<ll>> se; dp[x] = sp[x]; for (auto el : v[x]){ if (el != p){ dfs(el, x); se.insert({dp[el], el}); dp[x] += dp[el]; } } while (dp[x] > k){ dp[x] -= se.rbegin()->at(0); se.erase(*se.rbegin()); cnt++; } } int main(){ cin>>n>>k; sp.assign(n + 2, 0), dp.assign(n + 1, 0); v.assign(n + 1, vector<int>()); for (int i = 1; i <= n; i++){ cin>>sp[i]; } for (int i = 0; i < n - 1; i++){ cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } dfs(1, 0); cout<<cnt; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...