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

#TimeUsernameProblemLanguageResultExecution timeMemory
640579mouseyPaprike (COI18_paprike)C++17
100 / 100
120 ms15924 KiB
#include <bits/stdc++.h> #define ll long long #define vll vector<ll> #define vllp vector<pair<ll, ll> > #define vi vector <int> #define vip vector <pair <int, int> > #define db double #define ldb long double #define pdb pair <double, double> #define YES cout<<"YES" #define NO cout<<"NO" #define endl cout<<endl #define vv vector <vector <ll> > #define pll pair <ll, ll> #define pi pair <int, int> #define pb push_back #define f first #define s second using namespace std; const ll mod=1e9+7; const ll modx=998244353; const double eps=1e-9; const ll INF=INT_MAX; const ll INFINF=LLONG_MAX; const ll N=1e5; ll n, k, ans; ll price[N+5]; vll v[N+5]; void input() { cin >> n >> k; for(int i = 1; i <= n; i++) { cin >> price[i]; } for(int i = 1; i < n; i++) { ll x, y; cin >> x >> y; v[x].pb(y); v[y].pb(x); } } void dfs(ll u, ll pa) { vll vc; for(auto i: v[u]) { if(i==pa) continue; dfs(i, u); vc.pb(price[i]); } sort(vc.begin(), vc.end()); for(auto i: vc) { if(price[u]+i<=k) price[u]+=i, ans++; else break; } } void solve() { dfs(1, 0); cout << n-1-ans; } int main() { srand(time(0)); // auto start_time = chrono::high_resolution_clock::now(); // freopen("test.txt", "r", stdin); // freopen("out.txt", "w", stdout); // ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t=1; while(t--) { input(); solve(); } // auto end_time = chrono::high_resolution_clock::now(); // double duration = chrono::duration_cast<chrono::milliseconds>(end_time - start_time).count(); // cout << "\n[ " << duration << " ms ]\n"; } /* 7 1 1 1 1 1 2 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...