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>
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define rall(v) (v).rbegin(),(v).rend()
#define all(v) (v).begin(),(v).end()
#define OK cerr<<"OK"<<endl<<flush
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define y0 jahdakdh
#define y1 jahsadakdakdh
#define endl '\n'
const ll MOD=1e9+7;
using namespace std;
//mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
int n, ans, k;
ll dis[100005];
vector<int> g[100005];
void dfs(int v, int p)
{
vector<ll>e;
for(int u : g[v])
if(u != p)
{
dfs(u, v);
dis[v]+=dis[u];
e.pb(dis[u]);
}
sort(rall(e));
for(ll u : e)
{
if(dis[v]>k)
{
dis[v]-=u;
ans++;
}
}
}
int main()
{
SPEED;
cin>>n>>k;
for(int i=1; i<=n; i++)
cin>>dis[i];
for(int i=1; i<n; i++)
{
int u, v; cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
dfs(1, 0);
cout<<ans<<endl;
return 0;
}
# | 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... |