We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e2a78d4 commit 54f920cCopy full SHA for 54f920c
backtracking/coloring.py
@@ -111,3 +111,20 @@ def color(graph: list[list[int]], max_colors: int) -> list[int]:
111
return colored_vertices
112
113
return []
114
+
115
+if __name__ == "__main__":
116
+ # Example graph represented as an adjacency matrix
117
+ graph_example = [
118
+ [0, 1, 0, 0, 0],
119
+ [1, 0, 1, 0, 1],
120
+ [0, 1, 0, 1, 0],
121
+ [0, 0, 1, 0, 1],
122
123
+ ]
124
125
+ max_colors_example = 3
126
+ coloring_result = color(graph_example, max_colors_example)
127
+ if coloring_result:
128
+ print(f"Graph can be colored with {max_colors_example} colors: {coloring_result}")
129
+ else:
130
+ print(f"Graph cannot be colored with {max_colors_example} colors.")
0 commit comments