# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
732766 | bgnbvnbv | Paprike (COI18_paprike) | C++14 | 62 ms | 21068 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>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll res=0;
vector<ll>g[maxN];
ll ans[maxN];
ll h[maxN],k;
void dfs(ll u=1,ll p=0)
{
vector<ll>vec;
for(int v:g[u])
{
if(v!=p)
{
dfs(v,u);
vec.pb(ans[v]);
res++;
}
}
sort(vec.begin(),vec.end());
ans[u]=h[u];
for(int i=0;i<vec.size();i++)
{
if(ans[u]+vec[i]<=k)
{
ans[u]+=vec[i];
res--;
}
else break;
}
}
ll n;
void solve()
{
cin >> n>> k;
for(int i=1;i<=n;i++) cin >> h[i];
for(int i=1;i<n;i++)
{
ll u,v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
dfs();
//for(int i=1;i<=n;i++) cout << ans[i] <<' ';
cout << res;
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
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... |