Skip to content

Commit 76deea4

Browse files
VAIBHAVVARORAMaximSmolskiycclauss
authored
Add Extra edge cases (#12995)
* Add Extra edge cases * Update coloring.py --------- Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru> Co-authored-by: cclauss <3709715+cclauss@users.noreply.github.com>
1 parent 83a40c9 commit 76deea4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

backtracking/coloring.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ 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]
107115
"""
108116
colored_vertices = [-1] * len(graph)
109117

0 commit comments

Comments
 (0)