(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 #46198

#TimeUsernameProblemLanguageResultExecution timeMemory
46198BruteforcemanPaprike (COI18_paprike)C++11
100 / 100
227 ms42524 KiB
#include "bits/stdc++.h" using namespace std; vector <int> g[100010]; int h[100010]; long long sub[100010]; int k; int ans; void dfs(int x, int par) { sub[x] = h[x]; vector <long long> v; for(auto i : g[x]) { if(i - par) { dfs(i, x); v.push_back(sub[i]); } } sort(v.begin(), v.end()); for(auto i : v) { if(sub[x] + i > k) { ++ans; } else { sub[x] += i; } } } int main(int argc, char const *argv[]) { int n; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> h[i]; for(int i = 1; i < n; i++) { int p, q; cin >> p >> q; g[p].emplace_back(q); g[q].emplace_back(p); } dfs(1, 0); printf("%d\n", ans); 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...