Skip to content

Commit ce7bd0a

Browse files
Chilleesimonlindholm
authored andcommitted
shortened max clique by 4 lines (#129)
1 parent acce4e3 commit ce7bd0a

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

content/graph/MaximumClique.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@
1010
* faster for sparse graphs.
1111
* Status: fuzz-tested
1212
*/
13-
typedef bitset<200> B;
13+
typedef vector<bitset<200>> vb;
1414
struct Maxclique {
1515
double limit=0.025, pk=0;
1616
struct Vertex { int i, d=0; };
1717
typedef vector<Vertex> vv;
18-
vector<B> e;
18+
vb e;
1919
vv V;
2020
vector<vi> C;
2121
vi qmax, q, S, old;
22-
bool cut1(int pi, vi& A) {
23-
trav(i, A) if (e[pi][i]) return true;
24-
return false;
25-
}
2622
void init(vv& r) {
2723
trav(v,r) v.d = 0;
2824
trav(v, r) trav(j, r) v.d += e[v.i][j.i];
@@ -44,7 +40,8 @@ struct Maxclique {
4440
C[1].clear(), C[2].clear();
4541
trav(v, T) {
4642
int k = 1;
47-
while (cut1(v.i, C[k])) k++;
43+
auto f = [&](int i) { return e[v.i][i]; };
44+
while (any_of(all(C[k]), f)) k++;
4845
if (k > mxk) mxk = k, C[mxk + 1].clear();
4946
if (k < mnk) T[j++].i = v.i;
5047
C[k].push_back(v.i);
@@ -58,8 +55,7 @@ struct Maxclique {
5855
}
5956
}
6057
vi maxClique() { init(V), expand(V); return qmax; }
61-
Maxclique(vector<B> conn) :
62-
e(conn), C(sz(e) + 1), S(sz(e)+1), old(S) {
58+
Maxclique(vb conn) : e(conn), C(sz(e)+1), S(sz(C)), old(S) {
6359
rep(i,0,sz(e)) V.push_back({i});
6460
}
6561
};

fuzz-tests/graph/MaximumClique.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct timeit {
3030
int main() {
3131
rep(it, 0, 100000) {
3232
int n =(rand()%32)+1;
33-
vector<B> ed(n);
33+
vb ed(n);
3434
vector<maximal::B> ed2(n);
3535
int p =rand()%100;
3636
rep(i, 0, n) rep(j, 0, i) {

0 commit comments

Comments
 (0)