@@ -14,8 +14,7 @@ def is_safe(
14
14
True
15
15
"""
16
16
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 )
19
18
)
20
19
21
20
@@ -65,25 +64,25 @@ def graph_coloring(
65
64
66
65
doctest .testmod ()
67
66
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: " ))
70
69
graph = [[0 ] * num_vertices for _ in range (num_vertices )]
71
70
72
- print ("Enter the edges (u v):" )
71
+ print ("Enter edges (u v):" )
73
72
for _ in range (num_edges ):
74
73
try :
75
74
u , v = map (int , input ().split ())
76
75
if 0 <= u < num_vertices and 0 <= v < num_vertices :
77
76
graph [u ][v ] = 1
78
77
graph [v ][u ] = 1
79
78
else :
80
- print (f "Invalid edge: vertices must be between 0 and { num_vertices - 1 } ." )
79
+ print ("Invalid edge." )
81
80
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: " ))
83
84
84
- max_colors = int (input ("Enter maximum number of colors: " ))
85
-
86
85
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 ." )
88
87
else :
89
- print ("The graph cannot be colored with the given number of colors ." )
88
+ print ("Coloring not possible ." )
0 commit comments