| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 43916 | Yehezkiel | Paprike (COI18_paprike) | C++11 | 102 ms | 44092 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 fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long LL;
typedef pair<int,int> pii;
typedef long double LD;
const int MAXN=100000;
int n,k,harga[MAXN+5],ans=0;
vector <int> node[MAXN+5];
int hitung(int now,int par){
	vector <int> temp;
	LL sum=harga[now];
	for(auto v:node[now])
	{
		if(v==par)
			continue;
		temp.pb(hitung(v,now));
		sum+=temp.back();
	}
	sort(all(temp));
	
	int idx=temp.size()-1;
	while(sum>(LL) k)
	{
		sum-=temp[idx--];
		ans++;
	}
	return sum;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&harga[i]);
	for(int i=1;i<=n-1;i++)
	{
		int  u,v;
		scanf("%d%d",&u,&v);
		node[u].pb(v);
		node[v].pb(u);
	}
	hitung(1,0);
	cout<<ans<<endl;
}
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... | ||||
