Advertisement
TwITe

Untitled

Dec 2nd, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. bool isSafe(int node, int c) {
  2.     for (int i = 0; i < v[node].size(); i++)
  3.         if (v[node][i] && c == color[i]) {
  4.             return false;
  5.         }
  6.     return true;
  7. }
  8.  
  9. bool graph_coloring(int m, int node) {
  10.     for (auto i : v[node]) {
  11.         for (int c = 1; c <= m; c++) {
  12.             if (isSafe(node, c)) {
  13.                 color[node] = c;
  14.                 if (graph_coloring(m, i)) {
  15.                     return true;
  16.                 }
  17.                 color[node] = 0;
  18.             }
  19.         }
  20.     }
  21.     return false;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement