# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
296474 | BeanZ | Paprike (COI18_paprike) | C++14 | 81 ms | 18044 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>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
ll dp[N], cur[N], a[N];
ll k;
vector<ll> node[N];
void dfs(ll u, ll p){
vector<ll> v;
cur[u] = a[u];
for (auto j : node[u]){
if (j == p) continue;
dfs(j, u);
v.push_back(cur[j]);
dp[u] = dp[u] + dp[j];
}
sort(v.begin(), v.end());
for (int i = 0; i < (ll)v.size(); i++){
if ((cur[u] + v[i]) > k){
dp[u] = dp[u] + v.size() - i;
break;
}
cur[u] += v[i];
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("balance.in", "r")){
freopen("balance.in", "r", stdin);
freopen("balance.out", "w", stdout);
}
ll n;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++){
ll u, v;
cin >> u >> v;
node[u].push_back(v);
node[v].push_back(u);
}
dfs(1, 1);
cout << dp[1];
}
/*
*/
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... |