Skip to content

Instantly share code, notes, and snippets.

@hyuki
Created July 10, 2020 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki/a0285da6f334ae7f63ac9ccf1abb7241 to your computer and use it in GitHub Desktop.
Save hyuki/a0285da6f334ae7f63ac9ccf1abb7241 to your computer and use it in GitHub Desktop.
color_graph.rb - coloring bipartite graphs.
#!/usr/bin/env ruby
# See 「数学ガールの秘密ノート」第296回 https://link.hyuki.net/girlnote296
# by Hiroshi Yuki.
class Graph
def info(depth, s)
puts ' ' * depth + s
end
def another_color(color)
case color
when :white
:black
when :black
:white
else
abort "another_color error."
end
end
def push(u)
@stack.push(u)
# puts "#{u[:name]} is pushed. Stack is now [ #{@stack.map{|v| v[:name] }.join(', ')} ]."
end
def pop(expected)
u = @stack.pop
# puts "#{u[:name]} is popped. Stack is now [ #{@stack.map{|v| v[:name] }.join(', ')} ]."
if u != expected
abort "Unexpected result: #{u[:name]} is popped from the stack, but it should be = #{expected[:name]}"
end
end
def show_cycle_in_stack
a = []
@stack.reverse.each do |v|
a << v
break if a.size > 1 and a[0] == v
end
puts a.map {|v| "#{v[:name]}(#{v[:color]})"}.join(' - ')
end
def show_coloring
puts "White vertices are " + @vertices.values.select { |v| v[:color] == :white }.map {|v| v[:name] }.join(',') + "."
puts "Black vertices are " + @vertices.values.select { |v| v[:color] == :black }.map {|v| v[:name] }.join(',') + "."
end
def color_graph
info 0,"Start coloring #{@name}."
@vertices.values.each do |v|
v[:color] = nil
end
@vertices.values.each do |v|
if not v[:color]
info 0,"#{v[:name]} is not colored. Start coloring #{v[:name]} deeply."
if not color_dfs(1, v, :white)
info 0,"Graph #{@name} cannot be colored."
return false
end
else
info 0,"#{v[:name]} is already colored. No need coloring."
end
end
info 0,"Graph #{@name} is colored."
show_coloring
return true
end
def color_dfs(depth, u, color)
push(u)
if not u[:color]
info depth,"#{u[:name]} is not colored yet."
info depth,"#{u[:name]} is has #{u[:adj].size} adjacents."
u[:color] = color
info depth,"#{u[:name]} is colored in #{u[:color]}."
u[:adj].each do |v|
if not color_dfs(depth + 1, v, another_color(color))
return false
end
end
info depth,"#{u[:name]} is deeply colored successfully."
pop(u)
return true
elsif u[:color] == color
info depth,"#{u[:name]} is already colored in #{u[:color]}, and it is consistent."
pop(u)
return true
else
info depth,"#{u[:name]} is already colored in #{u[:color]}, but it should be colored in #{color}, failed."
puts "I found an odd cycle as follows:"
show_cycle_in_stack
pop(u)
return false
end
end
def initialize(name, edgelist)
@name = name
@vertices = {}
@stack = []
edgelist.each do |link|
if link.match(/^([^-]+)-([^-]+)$/)
uname = $1.to_s
vname = $2.to_s
abort if uname == vname
u = @vertices[uname]
if not u
u = { :name => uname, :adj => [] }
@vertices[uname] = u
end
v = @vertices[vname]
if not v
v = { :name => vname, :adj => [] }
@vertices[vname] = v
end
u[:adj] << v
v[:adj] << u
end
end
end
end
puts
Graph.new("sample", [
"1-2", "2-3",
"4-5", "5-6", "5-8", "4-7", "7-8",
]).color_graph
puts "↑「数学ガールの秘密ノート」第296回の例 https://link.hyuki.net/girlnote296"
puts
Graph.new("oddCycledGraph", [
"A-B",
"B-C",
"C-A",
]).color_graph
puts "↑奇数のサイクルがあるから色分けできない例"
puts
Graph.new("evenCycledGraph", [
"A-B",
"B-C",
"C-D",
"D-A",
]).color_graph
puts "↑偶数のサイクルだから色分けできる例"
puts
Graph.new("rhoGraph", [
"A-B",
"B-C",
"C-D",
"D-B",
]).color_graph
puts "↑ρの文字のように途中にサイクルができる例"
puts
Graph.new("binaryTree", [
"1-11",
"1-12",
"11-111",
"11-112",
"12-121",
"12-122",
"111-1111",
"111-1112",
]).color_graph
puts "↑名前の長さの偶奇で色分けされてる(ツリーの深さ)"
puts
Graph.new("cube", [
"000-001",
"000-010",
"000-100",
"001-011",
"001-101",
"010-011",
"010-110",
"100-101",
"100-110",
"011-111",
"101-111",
"110-111",
]).color_graph
puts "↑パリティになっている例"
puts
Graph.new("forest", [
"A-B",
"B-C",
"C-D",
"D-A",
"X-Y",
"X-Z",
"Y-W",
"Y-U",
]).color_graph
puts "↑二つの連結成分からなる例"
puts
srand(314)
s = []
100.times do |n|
a = ('A'.ord + rand(26)).chr
b = ('a'.ord + rand(26)).chr
s << "#{a}-#{b}"
end
Graph.new("bigPartite", s).color_graph
puts "↑ランダムな二部グラフ(大文字と小文字の間のみに辺がある)"
puts
@hyuki
Copy link
Author

hyuki commented Jul 10, 2020

Start coloring sample.
1 is not colored. Start coloring 1 deeply.
 1 is not colored yet.
 1 is has 1 adjacents.
 1 is colored in white.
  2 is not colored yet.
  2 is has 2 adjacents.
  2 is colored in black.
   1 is already colored in white, and it is consistent.
   3 is not colored yet.
   3 is has 1 adjacents.
   3 is colored in white.
    2 is already colored in black, and it is consistent.
   3 is deeply colored successfully.
  2 is deeply colored successfully.
 1 is deeply colored successfully.
2 is already colored. No need coloring.
3 is already colored. No need coloring.
4 is not colored. Start coloring 4 deeply.
 4 is not colored yet.
 4 is has 2 adjacents.
 4 is colored in white.
  5 is not colored yet.
  5 is has 3 adjacents.
  5 is colored in black.
   4 is already colored in white, and it is consistent.
   6 is not colored yet.
   6 is has 1 adjacents.
   6 is colored in white.
    5 is already colored in black, and it is consistent.
   6 is deeply colored successfully.
   8 is not colored yet.
   8 is has 2 adjacents.
   8 is colored in white.
    5 is already colored in black, and it is consistent.
    7 is not colored yet.
    7 is has 2 adjacents.
    7 is colored in black.
     4 is already colored in white, and it is consistent.
     8 is already colored in white, and it is consistent.
    7 is deeply colored successfully.
   8 is deeply colored successfully.
  5 is deeply colored successfully.
  7 is already colored in black, and it is consistent.
 4 is deeply colored successfully.
5 is already colored. No need coloring.
6 is already colored. No need coloring.
8 is already colored. No need coloring.
7 is already colored. No need coloring.
Graph sample is colored.
White vertices are 1,3,4,6,8.
Black vertices are 2,5,7.
↑「数学ガールの秘密ノート」第296回の例 https://link.hyuki.net/girlnote296

Start coloring oddCycledGraph.
A is not colored. Start coloring A deeply.
 A is not colored yet.
 A is has 2 adjacents.
 A is colored in white.
  B is not colored yet.
  B is has 2 adjacents.
  B is colored in black.
   A is already colored in white, and it is consistent.
   C is not colored yet.
   C is has 2 adjacents.
   C is colored in white.
    B is already colored in black, and it is consistent.
    A is already colored in white, but it should be colored in black, failed.
I found an odd cycle as follows:
A(white) - C(white) - B(black) - A(white)
Graph oddCycledGraph cannot be colored.
↑奇数のサイクルがあるから色分けできない例

Start coloring evenCycledGraph.
A is not colored. Start coloring A deeply.
 A is not colored yet.
 A is has 2 adjacents.
 A is colored in white.
  B is not colored yet.
  B is has 2 adjacents.
  B is colored in black.
   A is already colored in white, and it is consistent.
   C is not colored yet.
   C is has 2 adjacents.
   C is colored in white.
    B is already colored in black, and it is consistent.
    D is not colored yet.
    D is has 2 adjacents.
    D is colored in black.
     C is already colored in white, and it is consistent.
     A is already colored in white, and it is consistent.
    D is deeply colored successfully.
   C is deeply colored successfully.
  B is deeply colored successfully.
  D is already colored in black, and it is consistent.
 A is deeply colored successfully.
B is already colored. No need coloring.
C is already colored. No need coloring.
D is already colored. No need coloring.
Graph evenCycledGraph is colored.
White vertices are A,C.
Black vertices are B,D.
↑偶数のサイクルだから色分けできる例

Start coloring rhoGraph.
A is not colored. Start coloring A deeply.
 A is not colored yet.
 A is has 1 adjacents.
 A is colored in white.
  B is not colored yet.
  B is has 3 adjacents.
  B is colored in black.
   A is already colored in white, and it is consistent.
   C is not colored yet.
   C is has 2 adjacents.
   C is colored in white.
    B is already colored in black, and it is consistent.
    D is not colored yet.
    D is has 2 adjacents.
    D is colored in black.
     C is already colored in white, and it is consistent.
     B is already colored in black, but it should be colored in white, failed.
I found an odd cycle as follows:
B(black) - D(black) - C(white) - B(black)
Graph rhoGraph cannot be colored.
↑ρの文字のように途中にサイクルができる例

Start coloring binaryTree.
1 is not colored. Start coloring 1 deeply.
 1 is not colored yet.
 1 is has 2 adjacents.
 1 is colored in white.
  11 is not colored yet.
  11 is has 3 adjacents.
  11 is colored in black.
   1 is already colored in white, and it is consistent.
   111 is not colored yet.
   111 is has 3 adjacents.
   111 is colored in white.
    11 is already colored in black, and it is consistent.
    1111 is not colored yet.
    1111 is has 1 adjacents.
    1111 is colored in black.
     111 is already colored in white, and it is consistent.
    1111 is deeply colored successfully.
    1112 is not colored yet.
    1112 is has 1 adjacents.
    1112 is colored in black.
     111 is already colored in white, and it is consistent.
    1112 is deeply colored successfully.
   111 is deeply colored successfully.
   112 is not colored yet.
   112 is has 1 adjacents.
   112 is colored in white.
    11 is already colored in black, and it is consistent.
   112 is deeply colored successfully.
  11 is deeply colored successfully.
  12 is not colored yet.
  12 is has 3 adjacents.
  12 is colored in black.
   1 is already colored in white, and it is consistent.
   121 is not colored yet.
   121 is has 1 adjacents.
   121 is colored in white.
    12 is already colored in black, and it is consistent.
   121 is deeply colored successfully.
   122 is not colored yet.
   122 is has 1 adjacents.
   122 is colored in white.
    12 is already colored in black, and it is consistent.
   122 is deeply colored successfully.
  12 is deeply colored successfully.
 1 is deeply colored successfully.
11 is already colored. No need coloring.
12 is already colored. No need coloring.
111 is already colored. No need coloring.
112 is already colored. No need coloring.
121 is already colored. No need coloring.
122 is already colored. No need coloring.
1111 is already colored. No need coloring.
1112 is already colored. No need coloring.
Graph binaryTree is colored.
White vertices are 1,111,112,121,122.
Black vertices are 11,12,1111,1112.
↑名前の長さの偶奇で色分けされてる(ツリーの深さ)

Start coloring cube.
000 is not colored. Start coloring 000 deeply.
 000 is not colored yet.
 000 is has 3 adjacents.
 000 is colored in white.
  001 is not colored yet.
  001 is has 3 adjacents.
  001 is colored in black.
   000 is already colored in white, and it is consistent.
   011 is not colored yet.
   011 is has 3 adjacents.
   011 is colored in white.
    001 is already colored in black, and it is consistent.
    010 is not colored yet.
    010 is has 3 adjacents.
    010 is colored in black.
     000 is already colored in white, and it is consistent.
     011 is already colored in white, and it is consistent.
     110 is not colored yet.
     110 is has 3 adjacents.
     110 is colored in white.
      010 is already colored in black, and it is consistent.
      100 is not colored yet.
      100 is has 3 adjacents.
      100 is colored in black.
       000 is already colored in white, and it is consistent.
       101 is not colored yet.
       101 is has 3 adjacents.
       101 is colored in white.
        001 is already colored in black, and it is consistent.
        100 is already colored in black, and it is consistent.
        111 is not colored yet.
        111 is has 3 adjacents.
        111 is colored in black.
         011 is already colored in white, and it is consistent.
         101 is already colored in white, and it is consistent.
         110 is already colored in white, and it is consistent.
        111 is deeply colored successfully.
       101 is deeply colored successfully.
       110 is already colored in white, and it is consistent.
      100 is deeply colored successfully.
      111 is already colored in black, and it is consistent.
     110 is deeply colored successfully.
    010 is deeply colored successfully.
    111 is already colored in black, and it is consistent.
   011 is deeply colored successfully.
   101 is already colored in white, and it is consistent.
  001 is deeply colored successfully.
  010 is already colored in black, and it is consistent.
  100 is already colored in black, and it is consistent.
 000 is deeply colored successfully.
001 is already colored. No need coloring.
010 is already colored. No need coloring.
100 is already colored. No need coloring.
011 is already colored. No need coloring.
101 is already colored. No need coloring.
110 is already colored. No need coloring.
111 is already colored. No need coloring.
Graph cube is colored.
White vertices are 000,011,101,110.
Black vertices are 001,010,100,111.
↑パリティになっている例

Start coloring forest.
A is not colored. Start coloring A deeply.
 A is not colored yet.
 A is has 2 adjacents.
 A is colored in white.
  B is not colored yet.
  B is has 2 adjacents.
  B is colored in black.
   A is already colored in white, and it is consistent.
   C is not colored yet.
   C is has 2 adjacents.
   C is colored in white.
    B is already colored in black, and it is consistent.
    D is not colored yet.
    D is has 2 adjacents.
    D is colored in black.
     C is already colored in white, and it is consistent.
     A is already colored in white, and it is consistent.
    D is deeply colored successfully.
   C is deeply colored successfully.
  B is deeply colored successfully.
  D is already colored in black, and it is consistent.
 A is deeply colored successfully.
B is already colored. No need coloring.
C is already colored. No need coloring.
D is already colored. No need coloring.
X is not colored. Start coloring X deeply.
 X is not colored yet.
 X is has 2 adjacents.
 X is colored in white.
  Y is not colored yet.
  Y is has 3 adjacents.
  Y is colored in black.
   X is already colored in white, and it is consistent.
   W is not colored yet.
   W is has 1 adjacents.
   W is colored in white.
    Y is already colored in black, and it is consistent.
   W is deeply colored successfully.
   U is not colored yet.
   U is has 1 adjacents.
   U is colored in white.
    Y is already colored in black, and it is consistent.
   U is deeply colored successfully.
  Y is deeply colored successfully.
  Z is not colored yet.
  Z is has 1 adjacents.
  Z is colored in black.
   X is already colored in white, and it is consistent.
  Z is deeply colored successfully.
 X is deeply colored successfully.
Y is already colored. No need coloring.
Z is already colored. No need coloring.
W is already colored. No need coloring.
U is already colored. No need coloring.
Graph forest is colored.
White vertices are A,C,X,W,U.
Black vertices are B,D,Y,Z.
↑二つの連結成分からなる例

Start coloring bigPartite.
I is not colored. Start coloring I deeply.
 I is not colored yet.
 I is has 3 adjacents.
 I is colored in white.
  n is not colored yet.
  n is has 4 adjacents.
  n is colored in black.
   I is already colored in white, and it is consistent.
   W is not colored yet.
   W is has 5 adjacents.
   W is colored in white.
    k is not colored yet.
    k is has 2 adjacents.
    k is colored in black.
     W is already colored in white, and it is consistent.
     G is not colored yet.
     G is has 7 adjacents.
     G is colored in white.
      p is not colored yet.
      p is has 5 adjacents.
      p is colored in black.
       G is already colored in white, and it is consistent.
       D is not colored yet.
       D is has 2 adjacents.
       D is colored in white.
        m is not colored yet.
        m is has 2 adjacents.
        m is colored in black.
         D is already colored in white, and it is consistent.
         J is not colored yet.
         J is has 3 adjacents.
         J is colored in white.
          t is not colored yet.
          t is has 3 adjacents.
          t is colored in black.
           J is already colored in white, and it is consistent.
           O is not colored yet.
           O is has 4 adjacents.
           O is colored in white.
            q is not colored yet.
            q is has 7 adjacents.
            q is colored in black.
             O is already colored in white, and it is consistent.
             H is not colored yet.
             H is has 8 adjacents.
             H is colored in white.
              c is not colored yet.
              c is has 2 adjacents.
              c is colored in black.
               H is already colored in white, and it is consistent.
               Q is not colored yet.
               Q is has 7 adjacents.
               Q is colored in white.
                v is not colored yet.
                v is has 4 adjacents.
                v is colored in black.
                 Q is already colored in white, and it is consistent.
                 G is already colored in white, and it is consistent.
                 T is not colored yet.
                 T is has 3 adjacents.
                 T is colored in white.
                  v is already colored in black, and it is consistent.
                  n is already colored in black, and it is consistent.
                  o is not colored yet.
                  o is has 5 adjacents.
                  o is colored in black.
                   F is not colored yet.
                   F is has 2 adjacents.
                   F is colored in white.
                    h is not colored yet.
                    h is has 7 adjacents.
                    h is colored in black.
                     W is already colored in white, and it is consistent.
                     C is not colored yet.
                     C is has 2 adjacents.
                     C is colored in white.
                      h is already colored in black, and it is consistent.
                      r is not colored yet.
                      r is has 1 adjacents.
                      r is colored in black.
                       C is already colored in white, and it is consistent.
                      r is deeply colored successfully.
                     C is deeply colored successfully.
                     R is not colored yet.
                     R is has 4 adjacents.
                     R is colored in white.
                      h is already colored in black, and it is consistent.
                      d is not colored yet.
                      d is has 8 adjacents.
                      d is colored in black.
                       W is already colored in white, and it is consistent.
                       H is already colored in white, and it is consistent.
                       R is already colored in white, and it is consistent.
                       Q is already colored in white, and it is consistent.
                       Z is not colored yet.
                       Z is has 3 adjacents.
                       Z is colored in white.
                        u is not colored yet.
                        u is has 2 adjacents.
                        u is colored in black.
                         Z is already colored in white, and it is consistent.
                         R is already colored in white, and it is consistent.
                        u is deeply colored successfully.
                        d is already colored in black, and it is consistent.
                        s is not colored yet.
                        s is has 5 adjacents.
                        s is colored in black.
                         L is not colored yet.
                         L is has 5 adjacents.
                         L is colored in white.
                          j is not colored yet.
                          j is has 3 adjacents.
                          j is colored in black.
                           P is not colored yet.
                           P is has 2 adjacents.
                           P is colored in white.
                            j is already colored in black, and it is consistent.
                            i is not colored yet.
                            i is has 4 adjacents.
                            i is colored in black.
                             N is not colored yet.
                             N is has 5 adjacents.
                             N is colored in white.
                              i is already colored in black, and it is consistent.
                              w is not colored yet.
                              w is has 9 adjacents.
                              w is colored in black.
                               Y is not colored yet.
                               Y is has 5 adjacents.
                               Y is colored in white.
                                w is already colored in black, and it is consistent.
                                e is not colored yet.
                                e is has 5 adjacents.
                                e is colored in black.
                                 Y is already colored in white, and it is consistent.
                                 A is not colored yet.
                                 A is has 2 adjacents.
                                 A is colored in white.
                                  e is already colored in black, and it is consistent.
                                  a is not colored yet.
                                  a is has 6 adjacents.
                                  a is colored in black.
                                   S is not colored yet.
                                   S is has 4 adjacents.
                                   S is colored in white.
                                    a is already colored in black, and it is consistent.
                                    z is not colored yet.
                                    z is has 3 adjacents.
                                    z is colored in black.
                                     S is already colored in white, and it is consistent.
                                     J is already colored in white, and it is consistent.
                                     X is not colored yet.
                                     X is has 4 adjacents.
                                     X is colored in white.
                                      q is already colored in black, and it is consistent.
                                      h is already colored in black, and it is consistent.
                                      z is already colored in black, and it is consistent.
                                      w is already colored in black, and it is consistent.
                                     X is deeply colored successfully.
                                    z is deeply colored successfully.
                                    j is already colored in black, and it is consistent.
                                    a is already colored in black, and it is consistent.
                                   S is deeply colored successfully.
                                   S is already colored in white, and it is consistent.
                                   G is already colored in white, and it is consistent.
                                   A is already colored in white, and it is consistent.
                                   B is not colored yet.
                                   B is has 4 adjacents.
                                   B is colored in white.
                                    b is not colored yet.
                                    b is has 5 adjacents.
                                    b is colored in black.
                                     Q is already colored in white, and it is consistent.
                                     W is already colored in white, and it is consistent.
                                     B is already colored in white, and it is consistent.
                                     Q is already colored in white, and it is consistent.
                                     I is already colored in white, and it is consistent.
                                    b is deeply colored successfully.
                                    t is already colored in black, and it is consistent.
                                    p is already colored in black, and it is consistent.
                                    a is already colored in black, and it is consistent.
                                   B is deeply colored successfully.
                                   E is not colored yet.
                                   E is has 3 adjacents.
                                   E is colored in white.
                                    i is already colored in black, and it is consistent.
                                    h is already colored in black, and it is consistent.
                                    a is already colored in black, and it is consistent.
                                   E is deeply colored successfully.
                                  a is deeply colored successfully.
                                 A is deeply colored successfully.
                                 V is not colored yet.
                                 V is has 2 adjacents.
                                 V is colored in white.
                                  e is already colored in black, and it is consistent.
                                  l is not colored yet.
                                  l is has 2 adjacents.
                                  l is colored in black.
                                   V is already colored in white, and it is consistent.
                                   H is already colored in white, and it is consistent.
                                  l is deeply colored successfully.
                                 V is deeply colored successfully.
                                 Q is already colored in white, and it is consistent.
                                 N is already colored in white, and it is consistent.
                                e is deeply colored successfully.
                                q is already colored in black, and it is consistent.
                                f is not colored yet.
                                f is has 4 adjacents.
                                f is colored in black.
                                 Y is already colored in white, and it is consistent.
                                 H is already colored in white, and it is consistent.
                                 K is not colored yet.
                                 K is has 7 adjacents.
                                 K is colored in white.
                                  f is already colored in black, and it is consistent.
                                  q is already colored in black, and it is consistent.
                                  f is already colored in black, and it is consistent.
                                  w is already colored in black, and it is consistent.
                                  d is already colored in black, and it is consistent.
                                  d is already colored in black, and it is consistent.
                                  s is already colored in black, and it is consistent.
                                 K is deeply colored successfully.
                                 K is already colored in white, and it is consistent.
                                f is deeply colored successfully.
                                o is already colored in black, and it is consistent.
                               Y is deeply colored successfully.
                               N is already colored in white, and it is consistent.
                               O is already colored in white, and it is consistent.
                               U is not colored yet.
                               U is has 3 adjacents.
                               U is colored in white.
                                w is already colored in black, and it is consistent.
                                v is already colored in black, and it is consistent.
                                w is already colored in black, and it is consistent.
                               U is deeply colored successfully.
                               U is already colored in white, and it is consistent.
                               H is already colored in white, and it is consistent.
                               K is already colored in white, and it is consistent.
                               Q is already colored in white, and it is consistent.
                               X is already colored in white, and it is consistent.
                              w is deeply colored successfully.
                              o is already colored in black, and it is consistent.
                              s is already colored in black, and it is consistent.
                              e is already colored in black, and it is consistent.
                             N is deeply colored successfully.
                             E is already colored in white, and it is consistent.
                             P is already colored in white, and it is consistent.
                             H is already colored in white, and it is consistent.
                            i is deeply colored successfully.
                           P is deeply colored successfully.
                           L is already colored in white, and it is consistent.
                           S is already colored in white, and it is consistent.
                          j is deeply colored successfully.
                          s is already colored in black, and it is consistent.
                          o is already colored in black, and it is consistent.
                          s is already colored in black, and it is consistent.
                          p is already colored in black, and it is consistent.
                         L is deeply colored successfully.
                         Z is already colored in white, and it is consistent.
                         N is already colored in white, and it is consistent.
                         L is already colored in white, and it is consistent.
                         K is already colored in white, and it is consistent.
                        s is deeply colored successfully.
                       Z is deeply colored successfully.
                       G is already colored in white, and it is consistent.
                       K is already colored in white, and it is consistent.
                       K is already colored in white, and it is consistent.
                      d is deeply colored successfully.
                      u is already colored in black, and it is consistent.
                      p is already colored in black, and it is consistent.
                     R is deeply colored successfully.
                     F is already colored in white, and it is consistent.
                     E is already colored in white, and it is consistent.
                     X is already colored in white, and it is consistent.
                     G is already colored in white, and it is consistent.
                    h is deeply colored successfully.
                    o is already colored in black, and it is consistent.
                   F is deeply colored successfully.
                   Y is already colored in white, and it is consistent.
                   N is already colored in white, and it is consistent.
                   L is already colored in white, and it is consistent.
                   T is already colored in white, and it is consistent.
                  o is deeply colored successfully.
                 T is deeply colored successfully.
                 U is already colored in white, and it is consistent.
                v is deeply colored successfully.
                b is already colored in black, and it is consistent.
                c is already colored in black, and it is consistent.
                e is already colored in black, and it is consistent.
                d is already colored in black, and it is consistent.
                b is already colored in black, and it is consistent.
                w is already colored in black, and it is consistent.
               Q is deeply colored successfully.
              c is deeply colored successfully.
              q is already colored in black, and it is consistent.
              d is already colored in black, and it is consistent.
              f is already colored in black, and it is consistent.
              l is already colored in black, and it is consistent.
              g is not colored yet.
              g is has 1 adjacents.
              g is colored in black.
               H is already colored in white, and it is consistent.
              g is deeply colored successfully.
              w is already colored in black, and it is consistent.
              i is already colored in black, and it is consistent.
             H is deeply colored successfully.
             Y is already colored in white, and it is consistent.
             K is already colored in white, and it is consistent.
             I is already colored in white, and it is consistent.
             X is already colored in white, and it is consistent.
             M is not colored yet.
             M is has 1 adjacents.
             M is colored in white.
              q is already colored in black, and it is consistent.
             M is deeply colored successfully.
            q is deeply colored successfully.
            w is already colored in black, and it is consistent.
            t is already colored in black, and it is consistent.
            n is already colored in black, and it is consistent.
           O is deeply colored successfully.
           B is already colored in white, and it is consistent.
          t is deeply colored successfully.
          m is already colored in black, and it is consistent.
          z is already colored in black, and it is consistent.
         J is deeply colored successfully.
        m is deeply colored successfully.
        p is already colored in black, and it is consistent.
       D is deeply colored successfully.
       B is already colored in white, and it is consistent.
       L is already colored in white, and it is consistent.
       R is already colored in white, and it is consistent.
      p is deeply colored successfully.
      v is already colored in black, and it is consistent.
      d is already colored in black, and it is consistent.
      k is already colored in black, and it is consistent.
      a is already colored in black, and it is consistent.
      h is already colored in black, and it is consistent.
      x is not colored yet.
      x is has 1 adjacents.
      x is colored in black.
       G is already colored in white, and it is consistent.
      x is deeply colored successfully.
     G is deeply colored successfully.
    k is deeply colored successfully.
    h is already colored in black, and it is consistent.
    n is already colored in black, and it is consistent.
    d is already colored in black, and it is consistent.
    b is already colored in black, and it is consistent.
   W is deeply colored successfully.
   T is already colored in white, and it is consistent.
   O is already colored in white, and it is consistent.
  n is deeply colored successfully.
  q is already colored in black, and it is consistent.
  b is already colored in black, and it is consistent.
 I is deeply colored successfully.
n is already colored. No need coloring.
J is already colored. No need coloring.
t is already colored. No need coloring.
W is already colored. No need coloring.
k is already colored. No need coloring.
O is already colored. No need coloring.
q is already colored. No need coloring.
H is already colored. No need coloring.
c is already colored. No need coloring.
Y is already colored. No need coloring.
w is already colored. No need coloring.
D is already colored. No need coloring.
m is already colored. No need coloring.
h is already colored. No need coloring.
e is already colored. No need coloring.
A is already colored. No need coloring.
N is already colored. No need coloring.
i is already colored. No need coloring.
P is already colored. No need coloring.
j is already colored. No need coloring.
C is already colored. No need coloring.
d is already colored. No need coloring.
E is already colored. No need coloring.
S is already colored. No need coloring.
a is already colored. No need coloring.
z is already colored. No need coloring.
f is already colored. No need coloring.
L is already colored. No need coloring.
V is already colored. No need coloring.
s is already colored. No need coloring.
Q is already colored. No need coloring.
v is already colored. No need coloring.
G is already colored. No need coloring.
p is already colored. No need coloring.
b is already colored. No need coloring.
r is already colored. No need coloring.
R is already colored. No need coloring.
K is already colored. No need coloring.
B is already colored. No need coloring.
l is already colored. No need coloring.
Z is already colored. No need coloring.
u is already colored. No need coloring.
U is already colored. No need coloring.
F is already colored. No need coloring.
T is already colored. No need coloring.
o is already colored. No need coloring.
X is already colored. No need coloring.
g is already colored. No need coloring.
M is already colored. No need coloring.
x is already colored. No need coloring.
Graph bigPartite is colored.
White vertices are I,J,W,O,H,Y,D,A,N,P,C,E,S,L,V,Q,G,R,K,B,Z,U,F,T,X,M.
Black vertices are n,t,k,q,c,w,m,h,e,i,j,d,a,z,f,s,v,p,b,r,l,u,o,g,x.
↑ランダムな二部グラフ(大文字と小文字の間のみに辺がある)

@hyuki
Copy link
Author

hyuki commented Jul 10, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment