Skip to content

Commit 4f8b772

Browse files
Add Extra edge cases
1 parent c0ad5bb commit 4f8b772

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

backtracking/coloring.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ def color(graph: list[list[int]], max_colors: int) -> list[int]:
104104
>>> max_colors = 2
105105
>>> color(graph, max_colors)
106106
[]
107+
>>> color([], 2) # empty graph
108+
[]
109+
>>> color([[0]], 1) # single node, 1 color
110+
[0]
111+
>>> color([[0, 1], [1, 0]], 1) # 2 nodes, 1 color (impossible)
112+
[]
113+
>>> color([[0, 1], [1, 0]], 2) # 2 nodes, 2 colors (possible)
114+
[0, 1]
115+
107116
"""
108117
colored_vertices = [-1] * len(graph)
109118

0 commit comments

Comments
 (0)