# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71663 | aklo | Paprike (COI18_paprike) | C++14 | 199 ms | 20828 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;
int n,k,br=0,r,t;
int niz[100005],bio[100005];
pair <int, int> a[100005];
vector <int> v[100005];
vector <int> ve[100005];
int zbr=0;
void dfs(int x){
bio[x]=1;
ve[x].push_back(niz[x]);
for(int i=0; i<v[x].size(); i++){
if(bio[v[x][i]]==0){
dfs(v[x][i]);
//cout<<"DR";
//cout<<v[x][i]<<endl;
zbr=0;
for(int j=0; j<ve[v[x][i]].size(); j++){
zbr+=ve[v[x][i]][j];
}
ve[x].push_back(zbr);
}
}
r=0;
sort(ve[x].begin(), ve[x].end());
for(int i=0; i<ve[x].size(); i++){
r+=ve[x][i];
}
while(r>k){
r-=ve[x][ve[x].size()-1];
ve[x].pop_back();
br++;
}
}
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... |