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

#TimeUsernameProblemLanguageResultExecution timeMemory
650634ymmPaprike (COI18_paprike)C++17
100 / 100
60 ms21076 KiB
#include <bits/stdc++.h> #define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x) #define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x) typedef long long ll; typedef std::pair<int, int> pii; typedef std::pair<ll , ll > pll; using namespace std; const int N = 100'010; vector<int> A[N]; ll h[N]; int n; ll k; pll dfs(int v, int p) { int ans = 1; vector<ll> vec; for (int u : A[v]) { if (u != p) { auto [x, y] = dfs(u, v); ans += x; vec.push_back(y); } } sort(vec.begin(), vec.end()); ll sum = h[v]; for (auto x : vec) { if (sum + x > k) break; sum += x; ans -= 1; } return {ans, sum}; } int main() { cin.tie(0) -> sync_with_stdio(false); cin >> n >> k; Loop (i,0,n) cin >> h[i]; Loop (i,1,n) { int v, u; cin >> v >> u; --v; --u; A[v].push_back(u); A[u].push_back(v); } cout << dfs(0, -1).first - 1 << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...