# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88720 | igzi | Paprike (COI18_paprike) | C++17 | 80 ms | 44556 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>
#define maxN 100005
using namespace std;
vector <int> adj[maxN];
bool visited[maxN];
int ans[maxN],dp[maxN],n,k,h[maxN],i,a,b;
void dfs(int n){
vector <int> v;
ans[n]=0;
dp[n]=h[n];
visited[n]=true;
for(int i=0;i<adj[n].size();i++){
if(!visited[adj[n][i]]){
dfs(adj[n][i]);
ans[n]+=ans[adj[n][i]];
v.push_back(dp[adj[n][i]]);
}
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++){
if(dp[n]+v[i]>k) ans[n]++;
else{
dp[n]+=v[i];
}
}
}
int main()
{
std::ios_base::sync_with_stdio(false);
cin>>n>>k;
for(i=0;i<n;i++){
cin>>h[i];
}
for(i=0;i<n-1;i++){
cin>>a>>b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(0);
cout<<ans[0]<<endl;
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... |