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;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;
const int MAXN = 1e5 + 5;
int n, k, cost[MAXN], sol;
vector <int> E[MAXN];
void dfs(int x, int p = -1){
vector <int> tmp;
for(auto e : E[x]){
if(e == p) continue;
dfs(e, x);
tmp.pb(cost[e]);
}
sort(tmp.begin(), tmp.end());
for(auto it : tmp)
if(cost[x] + it > k)
sol ++;
else
cost[x] += it;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
REP(i, n)
cin >> cost[i];
REP(i, n - 1){
int a, b; cin >> a >> b; a --; b --;
E[a].pb(b); E[b].pb(a);
}
dfs(0);
cout << sol << "\n";
}
# | 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... |