-
-
Notifications
You must be signed in to change notification settings - Fork 50.5k
feat(backtracking): add m-coloring algorithm #13274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eacebd7
21ef5e1
2df824d
913c90a
16b6d78
d0909dc
152c0c0
7647b47
80cfe21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| def isSafe(node, color, graph, n, col): | ||
|
Check failure on line 1 in backtracking/m_coloring_problem.py
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Variable and function names should follow the Please provide type hint for the parameter: Please provide type hint for the parameter: Please provide type hint for the parameter: Please provide descriptive name for the parameter: Please provide type hint for the parameter: Please provide type hint for the parameter: |
||
| for k in range(n): | ||
| if graph[node][k] == 1 and col[k] == color: | ||
| return False | ||
| return True | ||
|
Check failure on line 5 in backtracking/m_coloring_problem.py
|
||
|
|
||
|
|
||
| def solve(node, col, m, n, graph): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: Please provide type hint for the parameter: Please provide descriptive name for the parameter: Please provide type hint for the parameter: Please provide descriptive name for the parameter: Please provide type hint for the parameter: Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: Please provide type hint for the parameter: Please provide descriptive name for the parameter: Please provide type hint for the parameter: Please provide descriptive name for the parameter: Please provide type hint for the parameter: Please provide type hint for the parameter: |
||
| if node == n: | ||
| return True | ||
| for c in range(1, m + 1): | ||
| if isSafe(node, c, graph, n, col): | ||
| col[node] = c | ||
| if solve(node + 1, col, m, n, graph): | ||
| return True | ||
| col[node] = 0 | ||
| return False | ||
|
|
||
|
|
||
| def graphColoring(graph, m, n): | ||
|
Check failure on line 20 in backtracking/m_coloring_problem.py
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Variable and function names should follow the Please provide type hint for the parameter: Please provide descriptive name for the parameter: Please provide type hint for the parameter: Please provide descriptive name for the parameter: Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Variable and function names should follow the Please provide type hint for the parameter: Please provide descriptive name for the parameter: Please provide type hint for the parameter: Please provide descriptive name for the parameter: Please provide type hint for the parameter: |
||
| col = [0] * n | ||
| if solve(0, col, m, n, graph): | ||
| return True | ||
| return False | ||
|
Check failure on line 24 in backtracking/m_coloring_problem.py
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| V = int(input()) | ||
| E = int(input()) | ||
| graph = [[0 for _ in range(V)] for _ in range(V)] | ||
| for _ in range(E): | ||
| u, v = map(int, input().split()) | ||
| graph[u][v] = 1 | ||
| graph[v][u] = 1 | ||
| m = int(input()) | ||
| if graphColoring(graph, m, V): | ||
| print("True") | ||
| else: | ||
| print("False") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function:
isSafe. If the function does not return a value, please provide the type hint as:def function() -> None:As there is no test file in this pull request nor any test function or class in the file
backtracking/m_coloring_problem.py, please provide doctest for the functionisSafeVariable and function names should follow the
snake_casenaming convention. Please update the following name accordingly:isSafePlease provide type hint for the parameter:
nodePlease provide type hint for the parameter:
colorPlease provide type hint for the parameter:
graphPlease provide descriptive name for the parameter:
nPlease provide type hint for the parameter:
nPlease provide type hint for the parameter:
col