From 88d04413ebaab961f849ac6ef3d6ff2179253d41 Mon Sep 17 00:00:00 2001 From: Gloria Mundi Date: Sat, 7 Jun 2025 21:20:34 +0200 Subject: make union find a struct, remove kruskal --- test/graph/cycleCounting.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'test/graph/cycleCounting.cpp') 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>& edges, int n) { int res = 0; for (int i = 1; i < (1ll << ssize(edges)); i++) { vector 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; -- cgit v1.2.3