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

#TimeUsernameProblemLanguageResultExecution timeMemory
89289lost_breathPaprike (COI18_paprike)C++14
100 / 100
118 ms35472 KiB
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define pb push_back #define mp make_pair #define pll pair<ll, ll> #define pii pair<int, int> #define ld long double #define pas(v) cout << #v << ' ' << v << endl #define all(v) v.begin(), v.end() #define fi first #define se second #define vi vector<ll> #define vvi vector<vi> using namespace std; int main() { cout.precision(30); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vi sp(n); for (auto &i : sp) cin >> i; vvi g(n); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--, b--; g[a].pb(b); g[b].pb(a); } function<pll(int, int)> dfs = [&](int v, int p) { vi have; ll sum = 0; ll ret = 0; for (auto u : g[v]) { if (u == p) continue; auto x = dfs(u, v); ll s = x.first; ll num = x.second; ret += num; have.pb(s); sum += s; } sum += sp[v]; if (sum <= k) return pll{sum, ret}; sort(all(have)); while (sum > k) { sum -= have.back(); ret++; have.pop_back(); } return pll{sum, ret}; }; auto res = dfs(0, -1); cout << res.se; 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...