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 :
2
8
"""
3
9
Check if it is safe to assign a color to a node.
4
10
@@ -7,10 +13,18 @@ def is_safe(node: int, color: int, graph: list[list[int]], num_vertices: int, co
7
13
>>> is_safe(0, 2, [[0,1],[1,0]], 2, [0,1])
8
14
True
9
15
"""
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
+ )
11
19
12
20
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 :
14
28
"""
15
29
Recursively try to color the graph using at most max_colors.
16
30
@@ -30,7 +44,9 @@ def solve(node: int, col: list[int], max_colors: int, num_vertices: int, graph:
30
44
return False
31
45
32
46
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 :
34
50
"""
35
51
Determine if the graph can be colored with at most max_colors.
36
52
0 commit comments