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

#TimeUsernameProblemLanguageResultExecution timeMemory
1117808vjudge1Paprike (COI18_paprike)C++17
0 / 100
1098 ms1048576 KiB
// author - alimammadzade #include <bits/stdc++.h> #define int long long using namespace std; struct dsu { vector<int> p; dsu(int n) { p.resize(n + 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; } }; signed main() { cin.tie(nullptr)->sync_with_stdio(0); // system("cls"), freopen("in.txt", "r", stdin); int n, k, res = 20; cin >> n >> k; vector<int> w(n + 1); vector<array<int, 2>> e(n - 1); for (int i = 1; i <= n; i++) cin >> w[i]; for (auto& [u, v] : e) cin >> u >> v; for (int i = 0; i < (1 << (n - 1)); i++) { dsu d(n); for (int j = 1; j <= n; j++) d.p[j] = -w[j]; for (int j = 0; j < n - 1; j++) if (i & (1 << j)) { int u = d._find(e[j][0]), v = d._find(e[j][1]); if (u != v) d._union(u, v); } bool ok = 1; for (int j = 1; j <= n; j++) ok &= (-d.p[d._find(j)] <= k); if (ok) res = min(res, n - 1 - __builtin_popcount(i)); } 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...