제출 #1117625

#제출 시각아이디문제언어결과실행 시간메모리
1117625vjudge1Paprike (COI18_paprike)C++17
100 / 100
46 ms19184 KiB
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define int long long using namespace std; const int sz = 1e5 + 5; int n, k, a[sz]; array<int, 2> dp[sz]; vector<int> g[sz]; void dfs(int v, int p) { dp[v] = {a[v], 0}; vector<int> vals; for(int i : g[v]) { if(i == p) continue; dfs(i, v); vals.push_back(dp[i][0]); dp[v][1] += dp[i][1] + 1; } sort(all(vals)); reverse(all(vals)); while(!vals.empty() && dp[v][0] + vals.back() <= k) { dp[v][0] += vals.back(); dp[v][1]--; vals.pop_back(); } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); 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[v].push_back(u); g[u].push_back(v); } dfs(1, 0); cout << dp[1][1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...