forked from ngiengkianyew/daily-coding-problem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem_056.py
35 lines (30 loc) · 813 Bytes
/
problem_056.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def can_color_graph(adjacency_matrix, k):
max_adjacencies = 0
for row in adjacency_matrix:
max_adjacencies = max(max_adjacencies, sum(row))
return k > max_adjacencies
adjacency_matrix_1 = [
[0, 1, 1, 1],
[1, 0, 1, 1],
[1, 1, 0, 1],
[1, 1, 1, 0],
]
assert can_color_graph(adjacency_matrix_1, 4)
assert not can_color_graph(adjacency_matrix_1, 3)
adjacency_matrix_2 = [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
]
assert can_color_graph(adjacency_matrix_2, 4)
assert can_color_graph(adjacency_matrix_2, 1)
adjacency_matrix_3 = [
[0, 1, 1, 0],
[1, 0, 0, 1],
[1, 0, 0, 1],
[0, 1, 1, 0],
]
assert can_color_graph(adjacency_matrix_3, 4)
assert can_color_graph(adjacency_matrix_3, 3)
assert not can_color_graph(adjacency_matrix_3, 2)