@@ -14,7 +14,8 @@ def is_safe(
14
14
True
15
15
"""
16
16
return all (
17
- not (graph [node ][k ] == 1 and col [k ] == color ) for k in range (num_vertices )
17
+ not (graph [node ][k ] == 1 and col [k ] == color )
18
+ for k in range (num_vertices )
18
19
)
19
20
20
21
@@ -44,7 +45,9 @@ def solve(
44
45
return False
45
46
46
47
47
- def graph_coloring (graph : list [list [int ]], max_colors : int , num_vertices : int ) -> bool :
48
+ def graph_coloring (
49
+ graph : list [list [int ]], max_colors : int , num_vertices : int
50
+ ) -> bool :
48
51
"""
49
52
Determine if the graph can be colored with at most max_colors.
50
53
@@ -58,15 +61,21 @@ def graph_coloring(graph: list[list[int]], max_colors: int, num_vertices: int) -
58
61
59
62
60
63
if __name__ == "__main__" :
61
- num_vertices = int (input ())
62
- num_edges = int (input ())
64
+ import doctest
65
+
66
+ doctest .testmod ()
67
+
68
+ num_vertices = int (input ("Enter number of vertices: " ))
69
+ num_edges = int (input ("Enter number of edges: " ))
63
70
graph = [[0 ] * num_vertices for _ in range (num_vertices )]
71
+
64
72
for _ in range (num_edges ):
65
73
u , v = map (int , input ().split ())
66
74
if 0 <= u < num_vertices and 0 <= v < num_vertices :
67
75
graph [u ][v ] = 1
68
76
graph [v ][u ] = 1
69
77
else :
70
78
raise ValueError ("Edge indices out of range" )
71
- max_colors = int (input ())
79
+
80
+ max_colors = int (input ("Enter maximum number of colors: " ))
72
81
print (graph_coloring (graph , max_colors , num_vertices ))
0 commit comments