Submission #712238

#TimeUsernameProblemLanguageResultExecution timeMemory
712238stevancvPaprike (COI18_paprike)C++14
100 / 100
66 ms21084 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 1e5 + 2; const int inf = 1e9; vector<int> g[N]; ll sum[N], k; int Dfs(int s, int e) { int ans = 0; vector<ll> v; for (int u : g[s]) { if (u == e) continue; ans += Dfs(u, s); v.push_back(sum[u]); } sort(v.rbegin(), v.rend()); while (!v.empty()) { if (sum[s] + v.back() > k) break; sum[s] += v.back(); v.pop_back(); } return ans + v.size(); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> sum[i]; for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } cout << Dfs(1, 0) << en; 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...