(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #210106

#TimeUsernameProblemLanguageResultExecution timeMemory
210106UtahaPaprike (COI18_paprike)C++14
100 / 100
86 ms25080 KiB
/*input 6 9 5 4 1 3 3 3 3 1 3 5 4 3 4 2 2 6 */ #include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ld,ld> pdd; #define IOS ios_base::sync_with_stdio(0); cin.tie(0) #define ALL(a) a.begin(),a.end() #define SZ(a) ((int)a.size()) #define F first #define S second #define REP(i,n) for(int i=0;i<((int)n);i++) #define eb emplace_back #define pb push_back #define MP(a,b) make_pair(a,b) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin()) #define EL cout<<'\n' #define BS(a,x) binary_search(ALL(a),x) template<typename T1,typename T2> ostream& operator<<(ostream& out,pair<T1,T2> P){ out<<'('<<P.F<<','<<P.S<<')'; return out; } template<typename T> ostream& operator<<(ostream& out,vector<T> V){ REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":""); return out; } //}}} const ll maxn=300005; const ll maxlg=20; const ll INF64=1e18; const int INF=0x3f3f3f3f; const ll MOD=ll(1e9+7); const ld PI=acos(-1); const ld eps=1e-9; //const ll p=880301; //const ll P=31; ll mypow(ll a,ll b){ ll res=1LL; while(b){ if(b&1) res=res*a%MOD; a=a*a%MOD; b>>=1; } return res; } ll a[maxn]; vector<int> edge[maxn]; int ans=0; ll n,k; ll rem[maxn]; void dfs(int u,int p){ vector<ll> tmp; for(int v:edge[u]) if(v!=p){ dfs(v,u); tmp.pb(rem[v]); } sort(ALL(tmp)); ll cur=a[u]; for(ll i:tmp){ if(cur+i>k){ ans++; } else cur+=i; } rem[u]=cur; } int main(){ IOS; cin>>n>>k; REP(i,n) cin>>a[i]; REP(i,n-1){ int u,v; cin>>u>>v; u--;v--; edge[u].pb(v); edge[v].pb(u); } dfs(0,-1); cout<<ans<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...