# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208347 | MatesV13 | Paprike (COI18_paprike) | C++11 | 93 ms | 22648 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;
long long n, k, h[100005], a, b, rez, ans;
vector<long long> c[100005];
vector<long long> l[100005];
long long lj[100005];
void dfs(int idx, int prev){
if (lj[idx]) return;
lj[idx]=h[idx];
for (int i=0; i<c[idx].size(); i++){
if (c[idx][i]==prev) continue;
dfs(c[idx][i], idx);
l[idx].push_back(lj[c[idx][i]]);
}
sort(l[idx].begin(), l[idx].end());
reverse(l[idx].begin(), l[idx].end());
for (int i=0; i<l[idx].size(); i++)
lj[idx]+=l[idx][i];
for (int i=0; lj[idx]>k; i++){
lj[idx]-=l[idx][i];
rez++;
}
return;
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i=1; i<=n; i++)
cin >> h[i];
for (int i=1; i<n; i++){
cin >> a >> b;
c[a].push_back(b);
c[b].push_back(a);
}
dfs(1, -1);
cout << rez;
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... |