import java.util.*; class GlasgowDoll extends Cliquer { int shallowestSelection; // the lowest indexed vertex that has been selected GlasgowDoll (int n,int[][]A,int[] degree,int[] weight,int style) { super(n,A,degree,weight,style); cpuTime = System.currentTimeMillis(); nodes = 0; c = new long[n]; adjacent = new int[n][n]; orderVertices(); for (int i=0;i P = new ArrayList(n); ArrayList C = new ArrayList(n); long pWeight = 0; for (int i=0;i C,ArrayList P,long cWeight,long pWeight){ nodes++; if (pWeight == 0 && cWeight > maxWeight){ saveSolution(C,cWeight); for (int i=0;i<=shallowestSelection;i++) c[i] = maxWeight; return; } if (P.isEmpty()) return; if (cWeight + pWeight <= maxWeight) return; int v = P.get(0); reject(C,P,cWeight,pWeight,v); accept(C,P,cWeight,v); } void accept(ArrayList C,ArrayList P,long cWeight,int v){ ArrayList newP = new ArrayList(P.size()); long newPweight = 0; for (int w : P) if (adjacent[v][w] == 1){ newP.add(w); newPweight = newPweight + weight[w]; } ArrayList newC = copy(C); newC.add(v); shallowestSelection = Math.min(shallowestSelection,v); if (shallowestSelection != v && cWeight + c[v] <= maxWeight) return; expand(newC,newP,cWeight + weight[v],newPweight); } void reject(ArrayList C,ArrayList P,long cWeight,long pWeight,int v){ ArrayList newP = copy(P); newP.remove((Integer) v); expand(C,newP,cWeight,pWeight - weight[v]); } ArrayList copy(ArrayList L){ ArrayList copy = new ArrayList(L.size()); for (int i : L) copy.add(i); return copy; } }