Skip to content

Commit 15b2b7b

Browse files
authored
Update m_coloring_problem.py
1 parent a841332 commit 15b2b7b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

backtracking/m_coloring_problem.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ def graph_coloring(graph: list[list[int]], max_colors: int,
5353
graph = [[0]*num_vertices for _ in range(num_vertices)]
5454
for _ in range(num_edges):
5555
u, v = map(int, input().split())
56-
graph[u][v] = 1
57-
graph[v][u] = 1
56+
if 0 <= u < num_vertices and 0 <= v < num_vertices:
57+
graph[u][v] = 1
58+
graph[v][u] = 1
59+
else:
60+
raise ValueError("Edge indices out of range")
5861
max_colors = int(input())
5962
col = [0]*num_vertices
6063
print(solve(0, col, max_colors, num_vertices, graph))

0 commit comments

Comments
 (0)