# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
963709 | Ivo_12 | Paprike (COI18_paprike) | C++98 | 57 ms | 23632 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>
#define ll long long
#define pb push_back
using namespace std;
struct node {
vector < int > chi;
int par = -1;
ll val = 0;
};
const int N = 100010;
node tree[N];
int n;
int k;
vector < int > edges[N];
int sol;
void dfs( int pos ) {
for(int i = 0; i < edges[pos].size(); i++) {
if(edges[pos][i]!=tree[pos].par) {
tree[edges[pos][i]].par=pos;
tree[pos].chi.pb(edges[pos][i]);
dfs(edges[pos][i]);
}
}
}
ll sumover( int pos ) {
vector < ll > chivals;
ll total = tree[pos].val;
for(int i = 0; i < tree[pos].chi.size(); i++) {
chivals.pb(sumover(tree[pos].chi[i]));
total+=chivals[i];
}
sort(chivals.begin(), chivals.end());
while(total>k) {
total-=(*--chivals.end());
chivals.pop_back();
sol++;
}
return total;
}
int main ( void ) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++) {
cin >> tree[i].val;
}
int a, b;
for(int i = 0; i < n-1; i++) {
cin >> a >> b;
edges[--a].pb(--b);
edges[b].pb(a);
}
dfs(0);
sumover(0);
cout << sol;
return 0;
}
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... |