# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
797009 | Trisanu_Das | Paprike (COI18_paprike) | C++17 | 92 ms | 23488 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;
const int MN = 1e5+5;
int n, k, i, arr[MN], u, v, ans, w[MN];
vector<int> vec[MN], adj[MN];
void dfs(int u,int p){
for(auto v : adj[u]){
if(v == p) continue;
dfs(v, u);
vec[u].push_back(w[v]);
}
w[u] = arr[u];
if(vec[u].size()){
sort(vec[u].begin() ,vec[u].end());
for(i = 0; i < vec[u].size() && w[u] + vec[u][i] <= k;i++) w[u] += vec[u][i];
ans += vec[u].size() - i;
}
}
int main(){
cin >> n >> k;
for(int i = 1; i < n + 1; i++) cin >> arr[i];
for(i = 1; i < n; i++){
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
cout << ans << '\n';
}
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... |