# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201803 | anonymous | Paprike (COI18_paprike) | C++14 | 95 ms | 15736 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>
#define MAXN 100005
using namespace std;
int N,K,wt[MAXN];
int ui,vi,ans;
vector <int> adj[MAXN];
int dfs(int u, int prev) {
vector <int> Val;
for (auto v: adj[u]) {
if (v != prev) {Val.push_back(dfs(v,u));}
}
sort(Val.begin(), Val.end());
int S=wt[u], r=0;
for (auto w: Val) {
if (S+w<=K) {S+=w, r++;}
else {break;}
}
ans+=Val.size() - r;
Val.clear();
return(S);
}
int main() {
//freopen("paprikein.txt","r",stdin);
scanf("%d %d",&N,&K);
for (int i=1; i<=N; i++) {
scanf("%d",&wt[i]);
}
for (int i=1; i<N; i++) {
scanf("%d %d",&ui,&vi);
adj[ui].push_back(vi);
adj[vi].push_back(ui);
}
dfs(1,0);
printf("%d\n", ans);
}
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... |