# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
531626 | Vladth11 | Paprike (COI18_paprike) | C++14 | 129 ms | 23812 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 debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 100001;
const ll VMAX = 1000001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll nr_of_bits = 21;
vector <int> v[NMAX];
pii scor[NMAX];
int h[NMAX], k;
void DFS(int node, int p){
ll s = h[node];
priority_queue <ll> pq;
int sum = 0, cati = 0;
for(auto x : v[node]){
if(x == p)
continue;
DFS(x, node);
s += scor[x].second;
sum += scor[x].first;
pq.push(scor[x].second);
}
ll cnt = 0;
while(pq.size() && s > k){
s -= pq.top();
cnt++;
pq.pop();
}
scor[node].first = cnt + sum;
scor[node].second = s;
}
int main() {
//ifstream cin("niceset.in");
//ofstream cout("niceset.out");
int n, i;
cin >> n >> k;
for(i = 1; i <= n; i++) cin >> h[i];
for(i = 1; i < n; i++){
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
DFS(1, 0);
cout << scor[1].first << "\n";
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... |