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

#TimeUsernameProblemLanguageResultExecution timeMemory
226047quocnguyen1012Paprike (COI18_paprike)C++14
100 / 100
76 ms17532 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define ar array using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 1e5 + 5, inf = 1e9; int N, K, a[maxn]; vector<int> adj[maxn]; pair<ll, int> solve(int u, int p = -1) { vector<pair<ll, int>> child; for(int v : adj[u]) if(v != p){ child.eb(solve(v, u)); } sort(child.begin(), child.end()); pair<ll, int> res = mp(a[u], 1); for(int i = 0; i < child.size(); ++i){ if(res.fi + child[i].fi <= K){ res.se += child[i].se - 1; res.fi += child[i].fi; } else{ res.se += child[i].se; } } //cerr << u << ' ' << res.se << '\n'; return res; } signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); #endif // LOCAL cin >> N >> K; for(int i = 1; i <= N; ++i) cin >> a[i]; for(int i = 1; i < N; ++i){ int u, v; cin >> u >> v; adj[u].eb(v); adj[v].eb(u); } cout << solve(1).se - 1; }

Compilation message (stderr)

paprike.cpp: In function 'std::pair<long long int, int> solve(int, int)':
paprike.cpp:27:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < child.size(); ++i){
                  ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...