# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
759355 | Hanksburger | Paprike (COI18_paprike) | C++17 | 38 ms | 19868 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;
int a[100005], b[100005], c[100005], n, m;
vector<int> adj[100005];
void dfs(int u, int p)
{
for (int v:adj[u])
if (v!=p)
dfs(v, u);
vector<int> vec;
for (int v:adj[u])
{
if (v!=p)
{
vec.push_back(c[v]);
b[u]+=b[v]+1;
}
}
c[u]=a[u];
sort(vec.begin(), vec.end());
for (int i=0; i<vec.size(); i++)
{
if (c[u]+vec[i]<=m)
{
b[u]--;
c[u]+=vec[i];
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i=1; i<=n; i++)
cin >> a[i];
for (int i=1; i<n; i++)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
cout << b[1];
}
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... |