# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1117609 | vjudge1 | Paprike (COI18_paprike) | C++17 | 81 ms | 19208 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.
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define pb push_back
#define iospeed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const ll sz = 1e5+5;
vl g[sz];
ll vis[sz], val[sz], subtree[sz], res = 0, n, m;
void dfs(ll node)
{
vis[node] = 1;
subtree[node] = val[node];
vl v;
for(auto u : g[node])
{
if(vis[u])
continue;
dfs(u);
v.pb(subtree[u]);
}
sort(all(v));
for(auto u : v)
{
if(subtree[node] + u <= m)
subtree[node] += u;
else
res++;
}
}
int main()
{
int i, j, x, y;
cin >> n >> m;
for(i = 1; i <= n; i++)
cin >> val[i];
for(i = 1; i <= n - 1; i++)
{
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
dfs(1);
cout << res << "\n";
}
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... |