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

#TimeUsernameProblemLanguageResultExecution timeMemory
640584anhduc2701Paprike (COI18_paprike)C++17
100 / 100
121 ms24544 KiB
#include <bits/stdc++.h> #define int long long using namespace std; typedef long long ll; const ll INF = 1e18; const int maxn = 1e6 + 5; const int mod = 1e9 + 7; using pi = pair<ll, ll>; using vi = vector<ll>; using pii = pair<pair<ll, ll>, ll>; #define all(x) x.begin(), x.end() #define len(x) ll(x.size()) #define eb emplace_back #define fi first #define se second #define mp make_pair #define pb push_back #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) int dp[100005]; vector<int> G[100005]; int ans = 0; int n; int a[100005]; int root; int k; priority_queue<int> pq[100005]; int dfs(int u, int p) { dp[u] = a[u]; for (auto v : G[u]) { if (v == p) continue; int d = dfs(v, u); pq[u].push(d); dp[u] += d; while (dp[u] > k) { dp[u] -= pq[u].top(); pq[u].pop(); ans++; } } return dp[u]; } signed main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n - 1; i++) { int x, y; cin >> x >> y; G[x].push_back(y); G[y].push_back(x); } dfs(1, 1); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...