# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44604 | ulna | Paprike (COI18_paprike) | C++11 | 1082 ms | 16360 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;
// why am I so weak
int n, k;
int a[100055];
long long dp[100055];
vector<int> g[100055];
int dfs(int v, int par = -1) {
dp[v] = a[v];
int res = 0;
for (auto u : g[v]) if (u != par) {
res += dfs(u, v);
dp[v] += dp[u];
}
sort(g[v].begin(), g[v].end(), [&] (int u, int v) {
return dp[u] > dp[v];
});
for (auto u : g[v]) {
if (dp[v] <= k) break;
res++;
dp[v] -= dp[u];
}
return res;
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i + 1 < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
x--, y--;
g[x].push_back(y);
g[y].push_back(x);
}
int res = INT_MAX;
for (int i = 0; i < n; i++) res = min(res, dfs(i));
printf("%d\n", res);
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... |