# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44057 | Lkvatashidze | Paprike (COI18_paprike) | C++11 | 190 ms | 21016 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;
void DFS(int,int);
int a[100005], dp[100005];
int n, Q;
vector < vector < int > > g;
int cnt;
int main() {
cin >> n >> Q;
g.resize(n+1);
for (int k=1; k<=n; k++)
cin >> a[k];
for (int k=1; k<n; k++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
DFS(1,-1);
cout << cnt;
return 0;
}
void DFS (int v, int p) {
dp[v]=a[v];
multiset < int > st;
for (int k=0; k<g[v].size(); k++) {
int to=g[v][k];
if (to==p) continue;
DFS(to,v);
st.insert(dp[to]);
}
while (!st.empty()) {
int q=(*st.begin());
if (dp[v]+q<=Q) {
dp[v]+=q;
} else {
cnt++;
}
st.erase(st.begin());
}
}
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... |