제출 #232775

#제출 시각아이디문제언어결과실행 시간메모리
232775pedy4000Paprike (COI18_paprike)C++14
24 / 100
67 ms19320 KiB
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int N = 1e5 + 5; int n, k, ans; int Arr[N]; vector <int> G[N]; int dfs (int v, int par = 0) { vector <int> vec; int sum = 0; for (int u: G[v]) if (u != par) { vec.push_back(dfs(u, v)); sum += vec.back(); } sum += Arr[v]; sort(vec.begin(), vec.end()); while (k < sum) { sum -= vec.back(); ans++; vec.pop_back(); } return sum; } int main() { ios::sync_with_stdio(false), cin.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) cin >> Arr[i]; for (int i = 0; i < n - 1; i++) { int v, u; cin >> v >> u; v--, u--; G[v].push_back(u); G[u].push_back(v); } dfs(0); cout << ans << "\n"; 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...