# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
363745 | arnold518 | Paprike (COI18_paprike) | C++14 | 92 ms | 20460 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;
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)
# | 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... |