Submission #1117694

#TimeUsernameProblemLanguageResultExecution timeMemory
1117694vjudge1Paprike (COI18_paprike)C++17
100 / 100
42 ms20772 KiB
#include <bits/stdc++.h> // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define int long long // #define ll long long #define pii pair<int, int> #define all(v) v.begin(), v.end() using namespace std; const int oo = 1e9 + 9; const int MAX = 2e5 + 5, LOGMAX = 20, B = 441, MOD = 998244353; int n, k; vector<int> g[MAX]; int arr[MAX]; int ans = 0; int dfs(int node, int p){ int a = arr[node]; vector<int> v; for(int to : g[node]){ if(to == p) continue; v.emplace_back(dfs(to, node)); a += v.back(); } sort(all(v)); while(a > k){ a -= v.back(); v.pop_back(); ans++; } return a; } void solve(){ cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> arr[i]; } for(int i = 1; i < n ; i++){ int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(1, 1); cout << ans << '\n'; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...