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

#TimeUsernameProblemLanguageResultExecution timeMemory
418801MohamedAhmed04Paprike (COI18_paprike)C++14
100 / 100
77 ms20676 KiB
#include <bits/stdc++.h> using namespace std ; const int MAX = 1e5 + 10 ; int arr[MAX] ; int n , k ; vector< vector<int> >adj(MAX) ; int ans = 0 ; int dfs(int node , int par) { long long sum = arr[node] ; vector<int>v ; for(auto &child : adj[node]) { if(child == par) continue ; int x = dfs(child , node) ; sum += x , v.push_back(x) ; } sort(v.begin() , v.end()) ; while(sum > k) ans++ , sum -= v.back() , v.pop_back() ; return sum ; } int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>k ; for(int i = 1 ; i <= n ; ++i) cin>>arr[i] ; for(int i = 0 ; i < n-1 ; ++i) { int x , y ; cin>>x>>y ; adj[x].push_back(y) ; adj[y].push_back(x) ; } dfs(1 , -1) ; return cout<<ans<<"\n" , 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...