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

#TimeUsernameProblemLanguageResultExecution timeMemory
699323bin9638Paprike (COI18_paprike)C++17
100 / 100
63 ms22668 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 100010 #define fs first #define sc second #define ii pair<int,int> #define iii pair<ii,int> #define ld long double #define pb push_back #define int ll int dp[N],n,k,a[N],ans=0; vector<int>g[N],s[N]; void DFS(int u,int p) { int sum=a[u]; for(auto v:g[u]) if(v!=p) { DFS(v,u); s[u].pb(dp[v]); sum+=dp[v]; } sort(s[u].begin(),s[u].end()); while(sum>k) { sum-=s[u].back(); s[u].pop_back(); ans++; } dp[u]=sum; } int32_t main() { // freopen("A.inp","r",stdin); // freopen("A.out","w",stdout); cin.tie(NULL); cout.tie(NULL); ios::sync_with_stdio(0); cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<n;i++) { int u,v; cin>>u>>v; g[u].pb(v); g[v].pb(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...