# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1026207 | vjudge1 | Paprike (COI18_paprike) | C++17 | 74 ms | 24972 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.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=100000;
long long int a[MAX_N];
vector<int>tree[MAX_N];
long long sub_tree_sum[MAX_N];
long long int k, rez=0;
long long dfs1(int node, int p)
{
sub_tree_sum[node]=a[node];
multiset<int>s;
for(int i=0; i<tree[node].size(); i++)
{
if(tree[node][i]!=p)
{
sub_tree_sum[node]+=dfs1(tree[node][i], node);
s.insert(sub_tree_sum[tree[node][i]]);
}
}
if(sub_tree_sum[node]>k)
{
long long sum=a[node];
for(auto it=s.begin(); it!=s.end(); it++)
{
if(sum+*it<=k)
{
sum+=*it;
}
else
{
rez++;
sub_tree_sum[node]-=*it;
}
}
}
return sub_tree_sum[node];
}
int main()
{
int n;
cin>>n>>k;
for(int i=0; i<n; i++)
{
cin>>a[i];
}
for(int i=0; i<n-1; i++)
{
int aa, bb;
cin>>aa>>bb;
aa--; bb--;
tree[aa].push_back(bb);
tree[bb].push_back(aa);
}
dfs1(0, 0);
cout<<rez;
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... |