1- def is_safe (node : int , color : int , graph : list [list [int ]], num_vertices : int , col : list [int ]) -> bool :
1+ def is_safe (
2+ node : int ,
3+ color : int ,
4+ graph : list [list [int ]],
5+ num_vertices : int ,
6+ col : list [int ],
7+ ) -> bool :
28 """
39 Check if it is safe to assign a color to a node.
410
@@ -7,10 +13,18 @@ def is_safe(node: int, color: int, graph: list[list[int]], num_vertices: int, co
713 >>> is_safe(0, 2, [[0,1],[1,0]], 2, [0,1])
814 True
915 """
10- return all (not (graph [node ][k ] == 1 and col [k ] == color ) for k in range (num_vertices ))
16+ return all (
17+ not (graph [node ][k ] == 1 and col [k ] == color ) for k in range (num_vertices )
18+ )
1119
1220
13- def solve (node : int , col : list [int ], max_colors : int , num_vertices : int , graph : list [list [int ]]) -> bool :
21+ def solve (
22+ node : int ,
23+ col : list [int ],
24+ max_colors : int ,
25+ num_vertices : int ,
26+ graph : list [list [int ]],
27+ ) -> bool :
1428 """
1529 Recursively try to color the graph using at most max_colors.
1630
@@ -30,7 +44,9 @@ def solve(node: int, col: list[int], max_colors: int, num_vertices: int, graph:
3044 return False
3145
3246
33- def graph_coloring (graph : list [list [int ]], max_colors : int , num_vertices : int ) -> bool :
47+ def graph_coloring (
48+ graph : list [list [int ]], max_colors : int , num_vertices : int
49+ ) -> bool :
3450 """
3551 Determine if the graph can be colored with at most max_colors.
3652
0 commit comments