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

#TimeUsernameProblemLanguageResultExecution timeMemory
44351aleksamiPaprike (COI18_paprike)C++14
100 / 100
116 ms44992 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 100005 long long a[MAXN]; long long sz[MAXN]; vector <int> g[MAXN]; int n,k; int ans=0; void dfs(int v,int p) { sz[v]=a[v]; vector <long long> vals; for(auto x:g[v]) { if(x!=p) { dfs(x,v); sz[v]+=sz[x]; vals.push_back(sz[x]); } } sort(vals.begin(),vals.end()); auto it = vals.end(); it--; while(sz[v]>k) { sz[v]-=*it; ans++; it--; } } int main() { ios_base::sync_with_stdio(false); cin >> n >> k; for(int i = 1; i <= n; i++)cin >> a[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); } dfs(1,0); cout << 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...