# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105512 | faustaadp | Paprike (COI18_paprike) | C++17 | 143 ms | 17484 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 pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
using namespace std;
ll n,k,i,a[101010],ta,tb,has,bes[101010];
vector<ll> v[101010];
void dfs(ll aa,ll bb)
{
bes[aa]=a[aa];
vector<ll> tem;
ll ii;
for(ii=0;ii<v[aa].size();ii++)
{
if(v[aa][ii]==bb)continue;
dfs(v[aa][ii],aa);
tem.pb(bes[v[aa][ii]]);
}
sort(tem.begin(),tem.end());
for(ii=0;ii<tem.size();ii++)
if(bes[aa]+tem[ii]<=k)
bes[aa]+=tem[ii];
else
has++;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>k;
for(i=1;i<=n;i++)cin>>a[i];
for(i=1;i<n;i++)
{
cin>>ta>>tb;
v[ta].pb(tb);
v[tb].pb(ta);
}
dfs(1,1);
cout<<has<<"\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... |