Submission #363745

#TimeUsernameProblemLanguageResultExecution timeMemory
363745arnold518Paprike (COI18_paprike)C++14
100 / 100
92 ms20460 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N;
vector<int> adj[MAXN+10];
ll A[MAXN+10], K;

ll dp[MAXN+10], ans;
void dfs(int now, int bef)
{
	vector<ll> V;
	for(int nxt : adj[now])
	{
		if(nxt==bef) continue;
		dfs(nxt, now);
		V.push_back(dp[nxt]);
	}
	sort(V.begin(), V.end());

	dp[now]=A[now];
	for(auto it : V)
	{
		if(dp[now]+it>K) ans++;
		else dp[now]+=it;
	}
}

int main()
{
	scanf("%d%lld", &N, &K);
	for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
	for(int i=1; i<N; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(1, 0);
	printf("%lld\n", ans);
}

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |  scanf("%d%lld", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
paprike.cpp:37:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
      |                          ~~~~~^~~~~~~~~~~~~~~
paprike.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |   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...