(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.

제출 #1117927

#제출 시각아이디문제언어결과실행 시간메모리
1117927vjudge1Paprike (COI18_paprike)C++17
100 / 100
51 ms19896 KiB
// author - alimammadzade #include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 1; vector<int> g[N]; int n, k, res, sz[N], val[N]; void dfs(int u, int p) { vector<int> subt; sz[u] = val[u]; for (int v : g[u]) if (v != p) { dfs(v, u); subt.push_back(sz[v]); sz[u] += sz[v]; } sort(subt.rbegin(), subt.rend()); for (int v : subt) if (sz[u] > k) sz[u] -= v, res++; else break; } signed main() { cin.tie(nullptr)->sync_with_stdio(0); // system("cls"), freopen("in.txt", "r", stdin); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> val[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, 1); cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...