# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72965 | badrovinho | Paprike (COI18_paprike) | C++14 | 13 ms | 2236 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 <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
int n,k;
int rez=0;
int hljut[10005];
int a[10005];
int b[10005];
vector <int> graf[10005];
int dfs(int x, int par){
vector <int> v;
for (int i = 0; i < (int)(graf[x]).size(); i++){
int child = graf[x][i];
if (child == par)continue;
v.push_back(dfs(child, x));
}
sort(v.begin(), v.end());
int sum = 0;
sum += hljut[x-1];
for (int j = 0; j < v.size(); j++) sum += v[j];
for (int i = v.size()-1; i >= 0; i--){
if (sum>k){
sum -= v[i];
rez++;
} else break;
}
return sum;
}
int main (){
cin >> n >> k;
for (int i=0; i<n; i++){
cin >> hljut[i];
}
for (int i=0; i<n-1; i++){
cin >> a[i] >> b[i];
graf[a[i]].push_back(b[i]);
graf[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... |