Submission #1104374

#TimeUsernameProblemLanguageResultExecution timeMemory
1104374overwatch9Paprike (COI18_paprike)C++17
100 / 100
82 ms19056 KiB
#include <bits/stdc++.h> using namespace std; int n, k; vector <vector <int>> adj; vector <int> vals; int ans; int dfs(int s, int p) { int x = vals[s]; vector <int> tp; for (auto i : adj[s]) { if (i == p) continue; tp.push_back(dfs(i, s)); } sort(tp.begin(), tp.end()); for (int i = 0; i < (int)tp.size(); i++) { if (tp[i] + x <= k) x += tp[i]; else ans++; } return x; } int main() { cin >> n >> k; adj.resize(n+1); vals.resize(n+1); for (int i = 1; i <= n; i++) cin >> vals[i]; for (int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) { if ((int)adj[i].size() == 1) { dfs(i, i); break; } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...