import java.util.*; public class MC { int[] degree; // degree of vertices int[][] A; // 0/1 adjacency matrix int n; // n vertices long nodes; // number of decisions long timeLimit; // milliseconds long cpuTime; // milliseconds int maxSize; // size of max clique int style; // used to flavor algorithm int[] solution; // as it says long checks; // number of tests for adjacency long[] whenFound; // whenFound[k] is the node count when clique of size k was found long[] nodesAtDepth; // number of recursive calls at depth MC (int n,int[][]A,int[] degree) { this.n = n; this.A = A; this.degree = degree; nodes = maxSize = 0; cpuTime = timeLimit = -1; style = 1; solution = new int[n]; checks = 0; whenFound = new long[n+1]; nodesAtDepth = new long[n]; } void search(){ cpuTime = System.currentTimeMillis(); nodes = 0; ArrayList C = new ArrayList(); ArrayList P = new ArrayList(n); for (int i=0;i C,ArrayList P){ if (timeLimit > 0 && System.currentTimeMillis() - cpuTime >= timeLimit) return; nodes++; nodesAtDepth[C.size()]++; for (int i=P.size()-1;i>=0;i--){ if (C.size() + P.size() <= maxSize) return; int v = P.get(i); C.add(v); ArrayList newP = new ArrayList(); for (int w : P) if (A[v][w] == 1) newP.add(w); if (C.size() > maxSize) saveSolution(C); if (!newP.isEmpty()) expand(C,newP); C.remove((Integer)v); P.remove((Integer)v); } } void saveSolution(ArrayList C){ Arrays.fill(solution,0); for (int i : C) solution[i] = 1; maxSize = C.size(); whenFound[maxSize] = nodes; } boolean adjacent(int v,int w){checks++; return A[v][w] == 1;} }