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

#TimeUsernameProblemLanguageResultExecution timeMemory
1117792vjudge1Paprike (COI18_paprike)C++17
13 / 100
16 ms848 KiB
// author - alimammadzade #include <bits/stdc++.h> using namespace std; int n, k; struct dsu { vector<int> p; dsu(int n) { p.assign(n + 1, -1); } int _find(int u) { return (p[u] < 0 ? u : p[u] = _find(p[u])); } void _union(int u, int v) { p[u] += p[v], p[v] = u; } }; void fiSubtask() { vector<int> h(n + 1); for (int i = 1; i <= n; i++) cin >> h[i]; vector<array<int, 2>> e; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; e.push_back({ u, v }); } int res = n; for (int i = 0; i < (1 << (n - 1)); i++) { dsu d(n); for (int j = 1; j <= n; j++) d.p[i] = -h[i]; for (int j = 0; j < n - 1; j++) if ((i & (1 << j)) and d._find(e[j][0]) != d._find(e[j][1])) d._union(d._find(e[j][0]), d._find(e[j][1])); map<int, int> mp; for (int i = 1; i <= n; i++) mp[d._find(i)] = -d.p[d._find(i)]; bool ok = 1; for (auto [a, b] : mp) if (b > k) { ok = 0; break; } if (ok) res = min(res, n - __builtin_popcount(i) - 1); } cout << res; } void seSubtask() { vector<int> h(n + 1); for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; } int res = 0, cur = 0; for (int i = 1; i <= n; i++) { if (cur + h[i] > k) res++, cur = 0; cur += h[i]; } cout << res; } signed main() { cin.tie(nullptr)->sync_with_stdio(0); // system("cls"), freopen("in.txt", "r", stdin); cin >> n >> k; if (n <= 15) fiSubtask(); else seSubtask(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...