diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2025-06-07 21:20:34 +0200 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2025-06-07 21:20:34 +0200 |
| commit | 88d04413ebaab961f849ac6ef3d6ff2179253d41 (patch) | |
| tree | 075e5f245f160cf3d8a03f728a4ebe41e010c5df /test/graph/cycleCounting.cpp | |
| parent | f8f53c2f9e63f0ac89b67dc4d413ec9a76415a73 (diff) | |
make union find a struct, remove kruskal
Diffstat (limited to 'test/graph/cycleCounting.cpp')
| -rw-r--r-- | test/graph/cycleCounting.cpp | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/test/graph/cycleCounting.cpp b/test/graph/cycleCounting.cpp index 9c7bf0c..82caf16 100644 --- a/test/graph/cycleCounting.cpp +++ b/test/graph/cycleCounting.cpp @@ -6,18 +6,14 @@ int naive(const vector<pair<int, int>>& edges, int n) { int res = 0; for (int i = 1; i < (1ll << ssize(edges)); i++) { vector<int> deg(n); - init(n); + UnionFind uf(n); int cycles = 0; for (int j = 0; j < ssize(edges); j++) { if (((i >> j) & 1) != 0) { auto [a, b] = edges[j]; deg[a]++; deg[b]++; - if (findSet(a) != findSet(b)) { - unionSets(a, b); - } else { - cycles++; - } + if (!uf.link(a, b)) cycles++; } } bool ok = cycles == 1; |
