# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
534024 | ivan_tudor | Paprike (COI18_paprike) | C++14 | 76 ms | 21076 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<bits/stdc++.h>
using namespace std;
struct dphelp{
int nrc;
long long csum;
bool operator <(dphelp oth) const{
return csum < oth.csum;
}
};
long long k;
const int N = 100005;
dphelp dp[N];
long long val[N];
vector<int> gr[N];
void dfs(int nod, int dad){
dp[nod].csum = val[nod];
dp[nod].nrc = 0;
vector<dphelp> smal;
for(auto x:gr[nod]){
if(x == dad)
continue;
dfs(x, nod);
dp[nod].nrc += dp[x].nrc;
smal.push_back(dp[x]);
}
sort(smal.begin(), smal.end());
for(int i = 0; i < smal.size(); i++){
if(dp[nod].csum + smal[i].csum <= k){
dp[nod].csum += smal[i].csum;
}
else
dp[nod].nrc++;
}
}
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n;
cin>>n>>k;
for(int i = 1; i<=n; i++)
cin>>val[i];
for(int i = 1; i<n; i++){
int x, y;
cin>>x>>y;
gr[x].push_back(y);
gr[y].push_back(x);
}
dfs(1, 0);
cout<<dp[1].nrc<<"\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... |