# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
967507 | lanaskarica | Paprike (COI18_paprike) | C++14 | 45 ms | 19284 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 ll long long
#define pii pair <int, int>
#define fi first
#define se second
const int MAXN = 1e5 + 5;
int n, k, rj, arr[MAXN];
vector <int> v[MAXN];
int rek(int x, int p) {
vector <int> r;
for (auto e : v[x]) {
if (e == p) continue;
r.push_back(rek(e, x));
}
// cout << "ispis: " << x << endl;
sort(r.begin(), r.end());
int zb = arr[x], y = 0;
for (int i = 0; i < r.size(); i++) {
// cout << r[i] << " ";
if (zb + r[i] > k) break;
zb += r[i]; y = i + 1;
// cout << ".";
}
// cout << endl;
// cout << zb << " " << r.size() << " " << y << endl;
rj += (r.size() - y);
return zb;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int a, b;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
rj = 0;
rek(1, 1);
cout << rj << "\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... |