# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
724946 | lukadupli | Paprike (COI18_paprike) | C++14 | 160 ms | 26100 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 ll;
const int MAXN = 3e5 + 5;
int n, k, arr[MAXN];
vector<int> adj[MAXN];
ll sum[MAXN];
int solve(int node, int par){
int ret = 0;
sum[node] = arr[node];
vector<int> v;
for(int nxt : adj[node]){
if(nxt != par){
ret += solve(nxt, node);
sum[node] += sum[nxt];
v.push_back(sum[nxt]);
}
}
sort(v.begin(), v.end(), greater<int>());
for(int i = 0; i < v.size() && sum[node] > k; i++){
sum[node] -= v[i];
ret++;
}
return ret;
}
int main()
{
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> arr[i];
for(int i = 0; i < n - 1; i++){
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
cout << solve(1, -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... |