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

#TimeUsernameProblemLanguageResultExecution timeMemory
87722fasterthanyouPaprike (COI18_paprike)C++14
100 / 100
198 ms45428 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--) #define pb(x) push_back(x) int n; long long k, s[100015], d[100015], res[100015]; vector<int> a[100015]; void dfs(int u, int p) { int child = 0; for(int v : a[u]) if(v != p) dfs(v, u), ++child; if (child<1) { d[u] = s[u]; return; } res[u] = 0; d[u] = s[u]; vector<long long> b; for(int v : a[u]) if(v != p) b.pb(d[v]), res[u] += res[v]; sort(b.begin(), b.end()); reverse(b.begin(), b.end()); while (!b.empty() && d[u]+b.back()<=k) d[u] += b.back(), b.pop_back(); res[u] += (int)b.size(); } int main() { cin >> n >> k; FOR(i,1,n+1) cin >> s[i]; FOR(i,0,n-1) { int u,v; cin >> u >> v; a[u].pb(v); a[v].pb(u); } dfs(1, -1); if (d[1]) ++res[1]; cout << res[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...