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 ll long long
#define f first
#define s second
#define x first
#define y second
#define elif else if
#define endl '\n'
#define all(x) begin(x), end(x)
int n,k,x,y,total;
int spice[100069];
vector<int> gph[100069];
bool done[100069];
int dfs(int node){
done[node]=true;
vector<int> vct;
for (int i:gph[node]) {
if (!done[i]) {
vct.push_back(dfs(i));
}
}
int cur=spice[node];
sort(all(vct));
for (int i : vct) {
if (cur+i<=k) {
cur+=i;
}
else{
total++;
}
}
return cur;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>k;
for (int i = 0; i < n; i++) {
cin>>spice[i];
}
for (int i = 0; i < n-1; i++) {
cin>>x>>y;
x--;y--;
gph[x].push_back(y);
gph[y].push_back(x);
}
dfs(0);
cout<<total<<endl;
return 0;
}
# | 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... |