# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
640569 | uylulu | Paprike (COI18_paprike) | C++14 | 53 ms | 18272 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>
using namespace std;
#define int long long
#define ld long double
#define endl "\n"
const int N = 1e5;
int n,k;
int num[N + 1],mn[N + 1];
vector<int> adj[N + 1];
int res = 0;
void dfs(int s,int pa) {
mn[s] = num[s];
vector<int> asd;
for(auto u : adj[s]) {
if(u == pa) continue;
dfs(u,s);
asd.push_back(mn[u]);
}
sort(asd.begin(),asd.end());
for(int i = 0;i < asd.size();i++) {
if(mn[s] + asd[i] > k) {
res += ((int)asd.size() - i);
break;
}
mn[s] += asd[i];
}
}
signed main() {
// freopen("in.txt","r",stdin);
// freopen("some.txt","w",stdout);
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>k;
for(int i = 1;i <= n;i++) cin>>num[i];
for(int i = 0;i < n - 1;i++) {
int x,y;
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
dfs(1,-1);
cout<<res<<endl;
}
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... |