# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
78955 | Charis02 | Paprike (COI18_paprike) | C++14 | 90 ms | 46184 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<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 100004
#define INF 1e9+7
using namespace std;
ll n,k,h[N],cuts,a,b;
ll val[N];
vector < vector < ll > > graph(N);
void calc(ll cur,ll par)
{
priority_queue < ll > pq;
rep(i,0,graph[cur].size())
{
if(graph[cur][i] == par)
continue;
calc(graph[cur][i],cur);
pq.push(-val[graph[cur][i]]);
}
val[cur] = h[cur];
while(!pq.empty())
{
ll to_add = -pq.top();
pq.pop();
if(to_add + val[cur] > k)
break;
cuts--;
val[cur] += to_add;
}
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> k;
rep(i,1,n+1)
{
cin >> h[i];
}
rep(i,0,n-1)
{
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
cuts = n-1;
calc(1,1);
cout << cuts << endl;
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... |