# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
785870 | AndiR | Paprike (COI18_paprike) | C++14 | 102 ms | 16080 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 <iostream>
#include <vector>
#include <queue>
using namespace std;
const int Nmax=100000;
int n, k, h[Nmax], sol;
vector <int> ad[Nmax];
priority_queue <int, vector<int>, greater<int>> pq;
void dfs(int node, int p){
for (int i=0; i<ad[node].size(); i++){
if (ad[node][i]!=p)
dfs(ad[node][i], node);
}
for (int i=0; i<ad[node].size(); i++){
if (ad[node][i]!=p)
pq.push(h[ad[node][i]]);
}
int newh=h[node];
while (!pq.empty()){
if (newh+pq.top()<=k)
newh+=pq.top();
else sol++;
pq.pop();
}
h[node]=newh;
}
int main()
{
cin>>n>>k;
for (int i=0; i<n; i++)
cin>>h[i];
int a, b;
for (int i=0; i<n-1; i++){
cin>>a>>b;
a--; b--;
ad[a].push_back(b);
ad[b].push_back(a);
}
dfs(0, -1);
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... |