제출 #43916

#제출 시각아이디문제언어결과실행 시간메모리
43916YehezkielPaprike (COI18_paprike)C++11
100 / 100
102 ms44092 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

paprike.cpp: In function 'int main()':
paprike.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
paprike.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&harga[i]);
   ~~~~~^~~~~~~~~~~~~~~~
paprike.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&u,&v);
   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...