# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71601 | algorithm16 | Paprike (COI18_paprike) | C++14 | 319 ms | 100676 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;
typedef long long int llint;
llint parent[3000000],brojac=0,b1=0;
vector <llint> c[3000000];
llint sum[3000000];
vector <llint> v;
llint n,k;
llint dfs(llint x) {
vector <llint> v2;
llint mini=10000000,b2=0,b3=0,b4=0,b5=0,sum3=0;
for(llint i=0;i<c[x].size();i++) {
if(parent[x]==c[x][i]) continue;
//cout <<x<<" "<<c[x][i]<<endl;
//sum2+=sum[c[x][i]];
/*if(mini==-1) mini=dfs(c[x][i],brojac2,x);
else if(dfs(c[x][i],brojac2,x)<mini) mini=dfs(c[x][i],brojac2,x);*/
//cout <<x<<" "<<dfs(c[x][i],0)<<endl;
int sum2=dfs(c[x][i]);
sum3+=sum2;
/*if(sum2+v[x]>k) {
b2+=1;
//b1+=sum2;
//sum[x]-=b1;
//cout <<v[x]<<" "<<sum2<<" "<<"uvjet1"<<endl;
brojac+=1;
sum[x]-=sum2;
}
else {
v.push_back()
b4+=sum2;
b3+=sum2;
b5+=1;
if(sum2<mini) mini=sum2;
}*/
v2.push_back(sum2);
}
/*b4-=mini;
llint s=c[x].size();
if(s-b2-1>1) {
//cout <<v[x]<<" "<<s-b2-1<<" "<<"uvjet2"<<endl;
b3-=b4;
//b1+=maxi;
brojac+=b5-1;
}
else if(x==0 && s-b2>1) {
//cout <<v[x]<<" "<<s-b2-1<<" "<<"uvjet2"<<endl;
b3-=b4;
//b1+=maxi;
brojac+=1;
}
//if(x==0) cout <<b3<<" "<<maxi<<endl;
sum[x]=v[x]+b3;
//sum[x]-=b1;*/
sum3+=v[x];
int index=v2.size()-1;
sort(v2.begin(),v2.end());
while(sum3>k) {
sum3-=v2[index];
index-=1;
brojac+=1;
}
return sum3;
}
void dfs2(llint x,llint par) {
parent[x]=par;
for(llint i=0;i<c[x].size();i++) {
if(c[x][i]==par) continue;
dfs2(c[x][i],x);
//sum[x]+=sum[c[x][i]];
}
//sum[x]+=v[x];
}
int main()
{
cin >> n >> k;
vector <pair<llint,llint> > y;
for(int i=0;i<n;i++) {
llint x;
cin >> x;
v.push_back(x);
}
for(llint i=0;i<n-1;i++) {
llint a,b;
cin >> a >> b;
y.push_back(make_pair(a-1,b-1));
c[a-1].push_back(b-1);
c[b-1].push_back(a-1);
}
dfs2(0,-1);
dfs(0);
/*for(int i=0;i<n;i++) {
cout <<sum[i]<<" ";
}
cout <<endl;*/
cout <<brojac;
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... |