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

#TimeUsernameProblemLanguageResultExecution timeMemory
230019dolphingarlicPaprike (COI18_paprike)C++14
100 / 100
69 ms19240 KiB
#include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) typedef long long ll; using namespace std; int n, k; ll a[100001]; vector<int> graph[100001]; int dfs(int node = 1, int parent = 0) { priority_queue<ll> pq; int ans = 0; for (int i : graph[node]) if (i != parent) { ans += dfs(i, node); pq.push(a[i]); a[node] += a[i]; } while (a[node] > k) { ans++; a[node] -= pq.top(); pq.pop(); } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; FOR(i, 1, n + 1) cin >> a[i]; FOR(i, 1, n) { int u, v; cin >> u >> v; graph[u].push_back(v); graph[v].push_back(u); } cout << dfs(); 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...