@@ -14,8 +14,7 @@ def is_safe(
1414 True
1515 """
1616 return all (
17- not (graph [node ][k ] == 1 and col [k ] == color )
18- for k in range (num_vertices )
17+ not (graph [node ][k ] == 1 and col [k ] == color ) for k in range (num_vertices )
1918 )
2019
2120
@@ -65,25 +64,25 @@ def graph_coloring(
6564
6665 doctest .testmod ()
6766
68- num_vertices = int (input ("Enter number of vertices: " ))
69- num_edges = int (input ("Enter number of edges: " ))
67+ num_vertices = int (input ("Enter vertices: " ))
68+ num_edges = int (input ("Enter edges: " ))
7069 graph = [[0 ] * num_vertices for _ in range (num_vertices )]
7170
72- print ("Enter the edges (u v):" )
71+ print ("Enter edges (u v):" )
7372 for _ in range (num_edges ):
7473 try :
7574 u , v = map (int , input ().split ())
7675 if 0 <= u < num_vertices and 0 <= v < num_vertices :
7776 graph [u ][v ] = 1
7877 graph [v ][u ] = 1
7978 else :
80- print (f "Invalid edge: vertices must be between 0 and { num_vertices - 1 } ." )
79+ print ("Invalid edge." )
8180 except ValueError :
82- print ("Invalid input format. Please enter two integers separated by a space." )
81+ print ("Invalid input." )
82+
83+ max_colors = int (input ("Enter max colors: " ))
8384
84- max_colors = int (input ("Enter maximum number of colors: " ))
85-
8685 if graph_coloring (graph , max_colors , num_vertices ):
87- print ("The graph can be colored with the given number of colors ." )
86+ print ("Coloring possible ." )
8887 else :
89- print ("The graph cannot be colored with the given number of colors ." )
88+ print ("Coloring not possible ." )
0 commit comments