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

#TimeUsernameProblemLanguageResultExecution timeMemory
640588baokhue232005Paprike (COI18_paprike)C++14
100 / 100
57 ms22224 KiB
/* #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") */ // lethal option #include<bits/stdc++.h> using namespace std; #define all(flg) flg.begin(), flg.end() #define int long long #define pb push_back #define fi first #define se second #define endl "\n" #define eb emplace_back #define ii pair<int, int> #define vi vector<int> #define PI 3.141592653589793238462643383279502884 #define ll long long #define ld long double #define for1(i, ff, gg) for(int i = ff; i <= gg; ++i) #define for2(i, ff, gg) for(int i = ff; i >= gg; --i) const ll mod = 1e9 + 7; const int maxN = 300005; const ll oo = 1e18 + 7; int n, a[maxN]; int x, y, z, k; int ans = 0; vector<int> vc[maxN]; int dfs(int node, int par){ vector<int> eli; int sum = a[node]; for(int cc : vc[node]) if(cc != par){ eli.pb(dfs(cc, node)); } sort(all(eli)); for(int cc : eli) sum += cc; while(sum > k){ sum -= eli.back(); eli.pop_back(); ++ans; } return sum; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> k; for1(i, 1, n) cin >> a[i]; for1(i, 2, n){ cin >> x >> y; vc[x].pb(y); vc[y].pb(x); } dfs(1, 0); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...