Submission #1043927

#TimeUsernameProblemLanguageResultExecution timeMemory
1043927vjudge1Paprike (COI18_paprike)C++17
38 / 100
1087 ms19836 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 1e5 + 10; ll n, k, a[N], sz[N], ans, tmp; vector<ll> g[N]; void dfs(ll v, ll p = -1){ sz[v] = a[v]; for (ll u : g[v]){ if (u == p) continue; dfs(u, v); sz[v] += sz[u]; } vector<int> vec; for (ll u : g[v]){ if (u == p) continue; vec.push_back(sz[u]); } sort(vec.begin(), vec.end()); while (sz[v] > k){ sz[v] -= vec.back(); vec.pop_back(); tmp++; } } int main(){ cin >> n >> k; for (ll i = 1; i <= n; i ++) cin >> a[i]; for (ll i = 1; i < n; i ++){ ll u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } ans = 1e9; for (ll v = 1; v <= n; v ++){ tmp = 0; dfs(v); ans = min(ans, tmp); } 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...