@@ -14,7 +14,8 @@ def is_safe(
1414 True
1515 """
1616 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 )
1819 )
1920
2021
@@ -44,7 +45,9 @@ def solve(
4445 return False
4546
4647
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 :
4851 """
4952 Determine if the graph can be colored with at most max_colors.
5053
@@ -58,15 +61,21 @@ def graph_coloring(graph: list[list[int]], max_colors: int, num_vertices: int) -
5861
5962
6063if __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: " ))
6370 graph = [[0 ] * num_vertices for _ in range (num_vertices )]
71+
6472 for _ in range (num_edges ):
6573 u , v = map (int , input ().split ())
6674 if 0 <= u < num_vertices and 0 <= v < num_vertices :
6775 graph [u ][v ] = 1
6876 graph [v ][u ] = 1
6977 else :
7078 raise ValueError ("Edge indices out of range" )
71- max_colors = int (input ())
79+
80+ max_colors = int (input ("Enter maximum number of colors: " ))
7281 print (graph_coloring (graph , max_colors , num_vertices ))
0 commit comments