제출 #1043913

#제출 시각아이디문제언어결과실행 시간메모리
1043913vjudge1Paprike (COI18_paprike)C++17
24 / 100
66 ms17592 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, k, a[N], sz[N], ans; vector<int> g[N]; void dfs(int v, int p = -1){ vector<int> vec; sz[v] = a[v]; for (int u : g[v]){ if (u == p) continue; dfs(u, v); sz[v] += sz[u]; vec.push_back(sz[u]); } sort(vec.begin(), vec.end()); while (sz[v] > k){ sz[v] -= vec.back(); vec.pop_back(); ans++; } } int main(){ cin >> n >> k; for (int i = 1; i <= n; i ++) cin >> a[i]; for (int i = 1; i < n; i ++){ int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(1); 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...