# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71637 | miljenko_jabucica | Paprike (COI18_paprike) | C++14 | 243 ms | 17132 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;
int n, k;
long long niz [100005];
vector <int> v[100005];
int a[100005];
int b[100005];
int rez = 0;
int dfs(int x, int par){
long long sum = 0;
vector<long long> lj_djeca;
if (v[x].size() == 1 && x != 1)return niz[x-1];
for (int i = 0; i < v[x].size(); ++i){
int node = v[x][i];
if (node == par)continue;
long long sum2 = dfs(node, x);
lj_djeca.push_back(sum2);
sum += sum2;
///cout <<node <<" " <<sum[node] <<endl;
}
sum += niz[x-1];
sort(lj_djeca.begin(), lj_djeca.end());
///cout <<"x -> " <<x <<endl;
///for (int i = 0; i < lj_djeca.size(); ++i)cout <<lj_djeca[i] <<" ";
///cout <<endl;
int i = 0;
while (sum>k){
sum -= lj_djeca[lj_djeca.size()-1];
lj_djeca.pop_back();
++rez;
}
return sum;
}
int main()
{
cin >>n >>k;
for (int i = 0; i < n; ++i)cin >>niz[i];
for (int i = 0; i < n-1; ++i){
cin >>a[i] >>b[i];
v[a[i]].push_back(b[i]);
v[b[i]].push_back(a[i]);
}
dfs(1, 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... |