# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
693273 | vuavisao | Paprike (COI18_paprike) | C++14 | 73 ms | 38316 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
using namespace std;
const ll N = 1e6 + 10;
ll n, k;
ll a[N];
vector<ll> g[N];
ll cost[N];
ll res;
void dfs(ll u, ll p) {
cost[u] = a[u];
for(const auto& v : g[u]) {
if(v == p) continue;
dfs(v, u);
}
sort(g[u].begin(), g[u].end(), [&] (ll lhs, ll rhs) -> bool {
return cost[lhs] < cost[rhs];
});
ll need = (ll) g[u].size();
for(const auto& v : g[u]) {
if(v == p) {
-- need;
continue;
}
if(cost[u] + cost[v] <= k) {
cost[u] += cost[v];
-- need;
}
}
res += need;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("COI18_PAPRIKE.inp", "r")) {
freopen("COI18_PAPRIKE.inp", "r", stdin);
freopen("COI18_PAPRIKE.out", "w", stdout);
}
cin >> n >> k;
for(ll i = 1; i <= n; ++ i) cin >> a[i];
for(ll i = 2; i <= n; ++ i) {
ll u, v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, 0);
cout << res;
return 0;
}
/// Code by vuavisao
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |