# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74361 | rKrPaN | Paprike (COI18_paprike) | C++98 | 213 ms | 53948 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>
using namespace std;
int n,k;
int ljut[100010];
vector <int> v[1000010];
int broj = 0;
/// DFS
int dfs(int x, int par){
vector <int> vec;
int summ= 0;
if (par != -1 && (int)v[x].size() == 1){
return ljut[x];
}
for (int i = 0; i < (int)v[x].size(); i++){
if (v[x][i] != par){
vec.push_back(dfs(v[x][i],x));
summ+= vec[(int)vec.size()-1];
}
}
sort(vec.begin(),vec.end());
summ+= ljut[x];
while(summ > k){
summ -= vec[(int)vec.size()-1];
vec.pop_back();
broj++;
}
return summ;
}
/// MAIN
int main (){
cin >> n >> k;
for (int i = 1; i <= n; i++){
cin >> ljut[i];
}
for (int j = 2; j <= n; j++){
int a,b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
int var = dfs(1,-1);
cout << broj << "\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... |