# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
706445 | mkupanovac | Paprike (COI18_paprike) | C++14 | 80 ms | 18420 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>
#define PB push_back
#define ll long long
using namespace std;
const int MAXN = (1e5 + 10);
ll n, k;
ll w[MAXN];
ll podstsum[MAXN];
vector<ll> graph[MAXN];
ll dfs(ll node, ll par){
ll trz = 0, sol = 0;
podstsum[node] += w[node];
vector<ll> djeca;
for (auto x: graph[node]){
if (x == par) continue;
sol += dfs(x, node);
podstsum[node] += podstsum[x];
djeca.PB(podstsum[x]);
}
if (podstsum[node] <= k){
return sol;
}
sort(djeca.begin(), djeca.end());
ll tr = djeca.size() - 1;
while (podstsum[node] > k){
podstsum[node] -= djeca[tr];
tr--;
sol++;
}
return sol;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> w[i + 1];
for (int i = 0; i < n - 1; i++){
ll a, b;
cin >> a >> b;
graph[a].PB(b);
graph[b].PB(a);
}
cout << dfs(1, 0) << "\n";
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... |