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

#TimeUsernameProblemLanguageResultExecution timeMemory
1117802vjudge1Paprike (COI18_paprike)C++17
0 / 100
5 ms2140 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; i++) d.p[i] = -w[i]; 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; }

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:16:11: warning: ignoring return value of 'int system(const char*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     system("cls"), freopen("in.txt", "r", stdin);
      |     ~~~~~~^~~~~~~
paprike.cpp:16:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     system("cls"), freopen("in.txt", "r", stdin);
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...