# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105574 | keko37 | Paprike (COI18_paprike) | C++14 | 129 ms | 21980 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;
typedef long long llint;
const int MAXN = 100005;
llint n, k;
llint val[MAXN], dp[MAXN];
vector <int> v[MAXN];
llint dfs (int x, int rod) {
llint res = val[x];
vector <llint> r;
for (int i=0; i<v[x].size(); i++) {
int sus = v[x][i];
if (sus == rod) continue;
r.push_back(dfs(sus, x));
res += r.back();
dp[x] += dp[sus];
}
sort(r.begin(), r.end());
while (res > k) {
res -= r.back();
dp[x]++;
r.pop_back();
}
return res;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i=1; i<=n; i++) {
cin >> val[i];
}
for (int i=0; i<n-1; i++) {
int a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
dfs(1, 0);
cout << dp[1];
return 0;
}
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... |