-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaximumClique.cpp
More file actions
39 lines (37 loc) · 1.34 KB
/
MaximumClique.cpp
File metadata and controls
39 lines (37 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
int MaximumIndependentSet(int n, const vector<long long> &g) {
int res = 0;
function<void (long long, int)> dfs = [&](long long remain, int cnt) {
for (bool update = true; update; ) {
update = false;
for (int i = 0; i < n; i ++) if (remain & (1LL << i)) {
int deg = __builtin_popcountll(remain & g[i]);
if (deg <= 1) {
cnt ++;
remain &= ~((1LL << i) | g[i]);
update = true;
}
}
}
res = max(res, cnt);
if (remain) {
int k = __builtin_ctzll(remain);
dfs(remain & ~(1LL << k), cnt);
dfs(remain & ~(g[k] | (1LL << k)), cnt + 1);
}
};
dfs((1LL << n) - 1, 0);
return res;
}
int MaximumClique(const int n, const vector<long long> &g) {
vector<long long> gg(n);
for (int i = 0; i < n; i ++) gg[i] = ~g[i];
return MaximumIndependentSet(n, gg);
}
int main() {
return 0;
}