fork(2) download
  1. #include <functional>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. /**
  7.  * Checks if node is adj to all nodes in subgraph.
  8.  *
  9.  * @param node the node to check for adjacency all other nodes in the subgraph
  10.  * @param subgraph an array of node integers
  11.  * @param len the length of the subgraph array
  12.  * @param adj a function accepting two integers corresponding to nodes and returns
  13.  * whether they are adjacent
  14.  * @returns whether node is adjacent to all nodes in subgraph.
  15.  */
  16. inline bool adj_all(int node, int* subgraph, int len, const function<bool(int, int)> &adj){
  17. for(int i = 0;i < len;i++){
  18. //cout << "Comparing with " << nodes[chain[i]] << "." << endl;
  19. if(i == node || !adj(subgraph[i], node)) {
  20. return false;
  21. }
  22. }
  23. return true;
  24. }
  25.  
  26. /**
  27.  * Finds the size of the maximal clique in the graph.
  28.  *
  29.  * @param num_nodes the number of nodes
  30.  * @param adj a function accepting two integers corresponding to nodes and returns
  31.  * whether they are adjacent
  32.  * @returns the size of the maximal clique.
  33.  */
  34. int max_clique(int num_nodes, const function<bool(int, int)> &adj)
  35. {
  36. if(num_nodes <= 0)
  37. return 0;
  38.  
  39. // Holds indices into nodes of current clique. Permuted to check every subgraph.
  40. // The stack is kept in sorted order (solely by nature of how it is incremented/permuted) so
  41. // as to only check each subgraph once.
  42. int stack[num_nodes + 1];
  43. stack[0] = 0;
  44.  
  45. // Holds the current index in the stack to permute.
  46. int index = 0;
  47.  
  48. // Holds the size of the largest clique found.
  49. int max_len = 0;
  50.  
  51. while(index >= 0) {
  52. bool complete = true;
  53.  
  54. // Down the tree. Add new nodes to the stack while we can find a neighbor to the
  55. // top node on the stack that is also adjacent to all nodes in the stack.
  56. while(complete) {
  57.  
  58. // Find a neighbor.
  59. complete = false; // This will stay false if no neighbor is found.
  60. for(int i = stack[index] + 1;!complete && i < num_nodes;i++) {
  61. if(adj_all(i, stack, index + 1, adj)) {
  62. stack[index + 1] = i; // Add this node to the stack.
  63. index++; // Advance the stack pointer.
  64. complete = true;
  65. }
  66. }
  67.  
  68. }
  69. complete = false;
  70.  
  71. if(index + 1 > max_len) {
  72. max_len = index + 1;
  73. }
  74.  
  75. while(!complete && index >= 0) {
  76. do {
  77. // If we get here, no suitable neighbor could be found for the top node on the
  78. // stack.
  79. // So we will permute the last neighbor on the stack.
  80. stack[index]++;
  81. complete = adj_all(stack[index], stack, index, adj);
  82. } while(!complete && stack[index] < num_nodes);
  83.  
  84. if(stack[index] >= num_nodes) {
  85. // If we get here, we've tried all possibilities for top node on the stack and
  86. // none of them were complete with the rest of the stack, so we need to pop the
  87. // node off the stack and start permuting the node below it.
  88. index--; // Pop the stack.
  89.  
  90. stack[index]++;
  91. complete = adj_all(stack[index], stack, index, adj);
  92. }
  93. }
  94. }
  95.  
  96. return max_len;
  97. }
  98.  
  99. /**
  100.  * Whether two nodes are adjacent.
  101.  */
  102. bool adj1(int n1, int n2) {
  103. static int connects[9][9] = {
  104. {0,1,1,1,0,0,1,1,1},
  105. {1,0,1,1,0,0,0,1,1},
  106. {1,1,0,1,1,1,0,0,1},
  107. {1,1,1,0,1,1,1,0,0},
  108. {0,0,1,1,0,1,1,0,0},
  109. {0,0,1,1,1,0,1,1,1},
  110. {1,0,0,1,1,1,0,1,1},
  111. {1,1,0,0,0,1,1,0,1},
  112. {1,1,1,0,0,1,1,1,0}};
  113.  
  114. return connects[n1][n2];
  115. }
  116.  
  117. /**
  118.  * Whether two nodes are adjacent.
  119.  */
  120. bool adj2(int n1, int n2) {
  121. static int connects[23][23] = {
  122. {0,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0},
  123. {0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1},
  124. {1,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,1,0},
  125. {0,1,0,0,1,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,0,1},
  126. {1,1,1,1,0,1,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,0},
  127. {0,1,1,1,1,0,1,1,0,1,1,1,0,1,1,1,0,0,1,1,1,1,1},
  128. {1,0,1,0,1,1,0,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1},
  129. {1,0,0,1,0,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1},
  130. {1,0,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1},
  131. {1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1,0,1,1,1,1},
  132. {1,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,0,0,1,1,1},
  133. {1,1,1,0,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,0,1,1,1},
  134. {1,1,1,0,0,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,1},
  135. {1,1,1,1,0,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1},
  136. {1,1,1,1,1,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,0,0,1},
  137. {1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,0,1,1,0,1,0,0,1},
  138. {1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,0,1,1,0,1,0,1},
  139. {1,1,1,1,1,0,0,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0},
  140. {0,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0,1,1,0,1,1,1,1},
  141. {1,0,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0,1,1,0,0,1,0},
  142. {0,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,1,1},
  143. {1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,0,0},
  144. {0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0}};
  145.  
  146. return connects[n1][n2];
  147. }
  148.  
  149. /**
  150.  * Whether two nodes are adjacent.
  151.  */
  152. bool adj3(int n1, int n2) {
  153. static int connects[41][41] = {
  154. {0,1,1,1,1,1,1,1,1,0,1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0,0,1,1,0,1,0,1,1,1,1,0,1,1,1,1,1},
  190. {1,1,1,1,0,1,0,1,0,0,1,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0,1,1,1,0,1,0,1,1,1,1,0,1,1,1,1},
  191. {1,1,1,1,1,0,1,0,1,0,0,1,1,1,0,1,1,1,1,1,1,0,0,0,1,1,1,1,0,1,0,1,1,1,1,1,1,0,1,1,1},
  192. {1,1,1,1,1,1,0,1,0,1,0,0,1,1,1,0,1,1,1,1,1,1,0,0,0,1,0,1,1,0,1,0,1,1,1,1,1,1,0,1,1},
  193. {1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,0,0,1,0,0,1,1,0,1,1,1,1,1,1,1,1,0,1},
  194. {1,1,1,1,1,1,1,1,0,1,1,1,0,1,0,0,1,1,1,1,1,1,1,1,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0}};
  195.  
  196. return connects[n1][n2];
  197. }
  198.  
  199. /**
  200.  * Whether two nodes are adjacent.
  201.  */
  202. bool adj4(int n1, int n2) {
  203. static int connects[51][51] = {
  204. {0,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1},
  205. {1,0,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1},
  206. {1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,0,0,1,0,0,1,1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1},
  207. {1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,0,0,1,0,0,1,1,1,1,1,1,1,0,0,0,1,0,0,1,1,1,1,0,1,0,1,1,1,1,1,1,1},
  208. {1,1,1,1,0,1,1,1,1,1,1,1,1,0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,0,0,1,1,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1},
  247. {1,1,1,0,1,0,1,1,1,0,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1},
  248. {1,1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1},
  249. {1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,0,0,0,1,1,1,1,1,1,1,0,0,1,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1},
  250. {1,1,1,1,1,1,0,1,0,1,1,1,1,0,0,1,0,0,0,1,1,1,1,1,1,1,0,0,1,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1},
  251. {1,1,1,1,1,1,1,0,1,0,1,1,1,1,0,0,1,0,0,0,1,1,1,1,1,1,1,0,0,1,0,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1},
  252. {1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,0,0,1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1},
  253. {1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1},
  254. {1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0}};
  255.  
  256.  
  257. return connects[n1][n2];
  258. }
  259.  
  260. /**
  261.  * Whether two nodes are adjacent.
  262.  */
  263. bool adj5(int n1, int n2) {
  264. static int connects[53][53] = {
  265. {0,1,1,1,1,0,0,1,1,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1,1,1,0,1,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,0},
  312. {0,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,0},
  313. {0,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1},
  314. {1,0,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,1,0,0,1,1,1,1,1,0,0,1,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1},
  315. {1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,0,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1},
  316. {1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,0,0,1,1,0,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1},
  317. {1,1,1,1,0,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,0,0,1,0,1,1,0,1,0,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,1,0}};
  318.  
  319.  
  320. return connects[n1][n2];
  321. }
  322.  
  323. int main() {
  324. cout << max_clique(9, adj1) << endl;
  325. cout << max_clique(23, adj2) << endl;
  326. cout << max_clique(41, adj3) << endl;
  327. cout << max_clique(51, adj4) << endl;
  328. cout << max_clique(53, adj5) << endl;
  329. return 0;
  330. }
Success #stdin #stdout 0.98s 3444KB
stdin
Standard input is empty
stdout
4
8
9
11
13