# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44615 | ulna | Paprike (COI18_paprike) | C++11 | 95 ms | 16744 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 (u != par) {
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);
}
printf("%d\n", dfs(0));
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... |