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

#TimeUsernameProblemLanguageResultExecution timeMemory
601358JasiekstrzPaprike (COI18_paprike)C++17
100 / 100
72 ms21476 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; const int N=1e5; int tab[N+10]; vector<int> e[N+10]; long long s[N+10]; int dfs(int x,int p,int k) { int ans=0; s[x]=tab[x]; vector<long long> sons; for(auto v:e[x]) { if(v!=p) { ans+=dfs(v,x,k); sons.push_back(s[v]); s[x]+=s[v]; } } sort(sons.begin(),sons.end()); while(s[x]>k) { ans++; s[x]-=sons.back(); sons.pop_back(); } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,k; cin>>n>>k; for(int i=1;i<=n;i++) cin>>tab[i]; for(int i=1;i<n;i++) { int a,b; cin>>a>>b; e[a].push_back(b); e[b].push_back(a); } cout<<dfs(1,0,k)<<"\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...