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

#TimeUsernameProblemLanguageResultExecution timeMemory
318467dufuPaprike (COI18_paprike)C++14
100 / 100
83 ms19940 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int ans, k; int f[100005] = {}; int dfs(vector<vector<int>> &m, vector<int> &w, int p){ int sum = w[p]; vector<int> down; for (int i : m[p]){ if (i != f[p]){ f[i] = p; down.emplace_back(dfs(m, w, i)); sum += down.back(); } } sort(down.begin(), down.end()); for (int i = down.size() - 1; sum > k; --i){ sum -= down[i]; ++ans; } // cout << p << ' ' << sum << '\n'; return sum; } main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n >> k; vector<int> w(n + 1); for (int i = 1; i <= n; ++i) cin >> w[i]; vector<vector<int>> m(n + 1); for (int i = 0; i < n - 1; ++i){ int a, b; cin >> a >> b; m[a].emplace_back(b); m[b].emplace_back(a); } ans = 0; dfs(m, w, 1); cout << ans << '\n'; }

Compilation message (stderr)

paprike.cpp:28:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | main(){
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...