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

#TimeUsernameProblemLanguageResultExecution timeMemory
1117844vjudge1Paprike (COI18_paprike)C++17
100 / 100
58 ms19892 KiB
#include <bits/stdc++.h> ///#define int long long #define endl '\n' #define fi first #define se second #define mp make_pair #define pll pair<long long, long long> #define mein ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; vector<int>x[100001]; long long dp[100001], val[100001]; long long k; int ans; void dfs(int n, int f){ dp[n] = val[n]; vector<int> v; for(int res: x[n]){ if(res != f){ dfs(res,n); dp[n] += dp[res]; v.push_back(dp[res]); } } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); int ix = 0; while(dp[n] > k){ ans++; dp[n] -=v[ix]; ix++; } } int main() { mein; int n; cin >> n >> k; for(int i = 1; i <= n; ++i){ cin >> val[i]; } for(int i = 0; i < n - 1; ++i){ int a,b; cin >> a >> b; x[a].push_back(b); x[b].push_back(a); } dfs(1,0); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...