diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-11-16 01:24:14 +0100 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-11-16 01:24:14 +0100 |
| commit | 98567ec798aa8ca2cfbcb85c774dd470f30e30d4 (patch) | |
| tree | 5113d5cc24d1ad5f93810b6442ce584a36950dc8 /content/graph/bronKerbosch.cpp | |
| parent | ad3856a6b766087df0036de0b556f4700a6498c9 (diff) | |
| parent | 8d11c6c8213f46f0fa19826917c255edd5d43cb1 (diff) | |
mzuenni tests
Diffstat (limited to 'content/graph/bronKerbosch.cpp')
| -rw-r--r-- | content/graph/bronKerbosch.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/content/graph/bronKerbosch.cpp b/content/graph/bronKerbosch.cpp new file mode 100644 index 0000000..0cfcc5f --- /dev/null +++ b/content/graph/bronKerbosch.cpp @@ -0,0 +1,24 @@ +using bits = bitset<64>; +vector<bits> adj, cliques; + +void addEdge(int a, int b) { + if (a != b) adj[a][b] = adj[b][a] = 1; +} + +void bronKerboschRec(bits R, bits P, bits X) { + if (P.none() && X.none()) { + cliques.push_back(R); + } else { + int q = min(P._Find_first(), X._Find_first()); + bits cands = P & ~adj[q]; + for (int i = 0; i < sz(adj); i++) if (cands[i]) { + R[i] = 1; + bronKerboschRec(R, P & adj[i], X & adj[i]); + R[i] = P[i] = 0; + X[i] = 1; +}}} + +void bronKerbosch() { + cliques.clear(); + bronKerboschRec({}, {(1ull << sz(adj)) - 1}, {}); +} |
