# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71672 | aklo | Paprike (COI18_paprike) | C++14 | 234 ms | 17184 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<algorithm>
#include<cstring>
#include<vector>
using namespace std;
long long n,k,br=0,r,t;
int niz[100005],bio[100005];
pair <int, int> a[100005];
vector <long long> v[100005];
int zbr=0;
int dfs(int x){
vector<long long> ve;
bio[x]=1;
for(int i=0; i<v[x].size(); i++){
if(bio[v[x][i]]==0){
//cout<<"DR";
//cout<<v[x][i]<<endl;
ve.push_back(dfs(v[x][i])) ;
}
}
r=0;
sort(ve.begin(), ve.end());
for(int i=0; i<ve.size(); i++){
r+=ve[i];
}
while(r+niz[x]>k){
r-=ve[ve.size()-1];
ve.pop_back();
br++;
}
return r+niz[x];
}
int main () {
cin>>n>>k;
for(int i=1; i<=n; i++){
cin>>niz[i];
}
for(int i=1; i<n; i++){
cin>>a[i].first>>a[i].second;
v[a[i].first].push_back(a[i].second);
v[a[i].second].push_back(a[i].first);
}
dfs(1);
//cout<<"JT";
//for(int i=1; i<=n; i++){
// r=0;
// for(int j=0; j<ve[i].size(); j++){
// r+=ve[i][j];
// }
// cout<<r<<endl;
//}
cout<<br;
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... |