# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
748277 | Username4132 | Paprike (COI18_paprike) | C++14 | 52 ms | 15584 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;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define PB push_back
const int MAXN=100010;
int n, k, ans, arr[MAXN], par[MAXN], dep[MAXN], order[MAXN];
vector<int> g[MAXN];
void dfs(int v, int p){
par[v]=p;
for(int to:g[v]) if(to!=p) {
dep[to]=dep[v]+1;
dfs(to, v);
}
}
int main(){
scanf("%d %d", &n, &k);
forn(i, n) scanf("%d", &arr[i]), order[i]=i;
forn(i, n-1){
int a, b; scanf("%d %d", &a, &b); --a, --b;
g[a].PB(b), g[b].PB(a);
}
dfs(0, 0);
sort(order, order+n, [](int a, int b){
return dep[a]!=dep[b]? dep[a]>dep[b] : arr[a]<arr[b];
});
forn(i, n-1){
int ind=order[i];
if(arr[ind]+arr[par[ind]]<=k) arr[par[ind]]+=arr[ind];
else ans++;
}
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... |