(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 #465458

#TimeUsernameProblemLanguageResultExecution timeMemory
465458BT21tataPaprike (COI18_paprike)C++17
100 / 100
65 ms19076 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...