# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242650 | vanic | Paprike (COI18_paprike) | C++14 | 97 ms | 17656 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 <cstdio>
#include <math.h>
#include <algorithm>
#include <set>
#include <stack>
#include <vector>
using namespace std;
const int maxn=1e5+5;
int val[maxn];
vector < int > ms[maxn];
int sol;
int n, k;
int dfs(int x, int prosl){
vector < int > svi;
for(int i=0; i<ms[x].size(); i++){
if(ms[x][i]!=prosl){
svi.push_back(dfs(ms[x][i], x));
}
}
sort(svi.begin(), svi.end());
int poc=val[x];
for(int i=0; i<svi.size(); i++){
if(poc+svi[i]<=k){
poc+=svi[i];
}
else{
sol+=svi.size()-i;
break;
}
}
return poc;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i=0; i<n; i++){
cin >> val[i];
}
int x, y;
for(int i=0; i<n-1; i++){
cin >> x >> y;
x--;
y--;
ms[x].push_back(y);
ms[y].push_back(x);
}
dfs(0, 0);
cout << sol << '\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... |