제출 #1081381

#제출 시각아이디문제언어결과실행 시간메모리
1081381juicyPaprike (COI18_paprike)C++17
100 / 100
42 ms23444 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 1e5 + 5; int n, k; int a[N], cnt[N]; long long dp[N]; vector<int> g[N]; void dfs(int u, int p) { priority_queue<long long> pq; dp[u] = a[u]; for (int v : g[u]) { if (v ^ p) { dfs(v, u); pq.push(dp[v]); dp[u] += dp[v]; cnt[u] += cnt[v]; } } while (dp[u] > k) { dp[u] -= pq.top(); pq.pop(); ++cnt[u]; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(1, 1); cout << cnt[1]; 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...