(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #488668

#TimeUsernameProblemLanguageResultExecution timeMemory
488668JovanBPaprike (COI18_paprike)C++17
100 / 100
47 ms20680 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 100000; vector <int> graf[N+5]; int val[N+5]; pair <int, int> dfs(int v, int p, int k){ int res = 0; vector <int> vec; for(auto c : graf[v]){ if(c == p) continue; pair <int, int> x = dfs(c, v, k); res += x.first; vec.push_back(x.second); } sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end()); while(vec.size() && val[v] + vec.back() <= k) val[v] += vec.back(), vec.pop_back(); res += vec.size(); return {res, val[v]}; } int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, k; cin >> n >> k; for(int i=1; i<=n; i++) cin >> val[i]; for(int i=1; i<n; i++){ int a, b; cin >> a >> b; graf[a].push_back(b); graf[b].push_back(a); } cout << dfs(1, 0, k).first << "\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...