@@ -21,13 +21,17 @@ def valid_coloring(
21
21
If all neighbours validate the constraint return True
22
22
23
23
Parameters:
24
- neighbours (list[int]): The list representing which vertices are adjacent to the current vertex.
25
- 1 indicates an edge between the current vertex and the neighbour.
26
- colored_vertices (list[int]): List of current color assignments for all vertices (-1 means uncolored).
24
+ neighbours (list[int]): The list representing which vertices
25
+ are adjacent to the current vertex.
26
+ 1 indicates an edge between the current vertex
27
+ and the neighbour.
28
+ colored_vertices (list[int]): List of current color assignments for all vertices
29
+ (-1 means uncolored).
27
30
color (int): The color we are trying to assign to the current vertex.
28
31
29
32
Returns:
30
- bool: True if the vertex can be safely colored with the given color, otherwise False.
33
+ bool: True if the vertex can be safely colored with the given color,
34
+ otherwise False.
31
35
32
36
Examples:
33
37
>>> neighbours = [0, 1, 0, 1, 0]
@@ -73,10 +77,12 @@ def util_color(
73
77
74
78
Parameters:
75
79
graph (list of list of int): Adjacency matrix representing the graph.
76
- graph[i][j] is 1 if there is an edge between vertex i and j.
80
+ graph[i][j] is 1 if there is an edge
81
+ between vertex i and j.
77
82
max_colors (int): Maximum number of colors allowed (m in the m-coloring problem).
78
83
colored_vertices (list of int): Current color assignments for each vertex.
79
- -1 indicates that the vertex has not been colored yet.
84
+ -1 indicates that the vertex has not been colored
85
+ yet.
80
86
index (int): The current vertex index being processed.
81
87
82
88
Returns:
@@ -120,7 +126,8 @@ def util_color(
120
126
def color (graph : list [list [int ]], max_colors : int ) -> list [int ]:
121
127
"""
122
128
Attempts to color the graph with at most max_colors colors such that no two adjacent
123
- vertices have the same color. If it is possible, returns the list of color assignments;
129
+ vertices have the same color.
130
+ If it is possible, returns the list of color assignments;
124
131
otherwise, returns an empty list.
125
132
126
133
Parameters:
@@ -129,7 +136,8 @@ def color(graph: list[list[int]], max_colors: int) -> list[int]:
129
136
130
137
Returns:
131
138
list of int: List of color assignments if the graph can be colored using max_colors.
132
- Each index in the list represents the color assigned to the corresponding vertex.
139
+ Each index in the list represents the color assigned
140
+ to the corresponding vertex.
133
141
If coloring is not possible, returns an empty list.
134
142
135
143
Examples:
0 commit comments