Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backtracking/coloring.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def color(graph: list[list[int]], max_colors: int) -> list[int]:
>>> max_colors = 2
>>> color(graph, max_colors)
[]
>>> color([], 2) # empty graph
[]
>>> color([[0]], 1) # single node, 1 color
[0]
>>> color([[0, 1], [1, 0]], 1) # 2 nodes, 1 color (impossible)
[]
>>> color([[0, 1], [1, 0]], 2) # 2 nodes, 2 colors (possible)
[0, 1]

"""
colored_vertices = [-1] * len(graph)

Expand Down
Loading