def display(matrix, countries):
for i in range(countries):
for j in range(countries):
print(matrix[i][j], end = " ")
print()
def solve(matrix, countries):
colors = [0] * countries
for i in range(1, countries):
col = -1
ok = False
while ok is not True:
col += 1
ok = True
for k in range( i ):
if matrix[k][i] == 1 and colors[k] == col:
ok = False
colors[i] = col
final_list = list(map(lambda x: x+1, colors))
print(final_list)
def fn():
matrix = [[0,1,1,1,0,0,1],
[1,0,1,1,0,0,0],
[1,1,0,1,1,0,1],
[1,1,1,0,1,0,1],
[0,0,1,1,0,1,1],
[0,0,0,0,1,0,1],
[1,0,1,1,1,1,0]]
countries = 7
display(matrix, countries)
solve(matrix, countries)
fn()
ZGVmIGRpc3BsYXkobWF0cml4LCBjb3VudHJpZXMpOgoKICAgIGZvciBpIGluIHJhbmdlKGNvdW50cmllcyk6CgogICAgICAgIGZvciBqIGluIHJhbmdlKGNvdW50cmllcyk6CgogICAgICAgICAgICBwcmludChtYXRyaXhbaV1bal0sIGVuZCA9ICIgIikKICAgICAgICBwcmludCgpCgpkZWYgc29sdmUobWF0cml4LCBjb3VudHJpZXMpOgoKICAgIGNvbG9ycyA9IFswXSAqIGNvdW50cmllcwoKICAgIGZvciBpIGluIHJhbmdlKDEsIGNvdW50cmllcyk6CgogICAgICAgIGNvbCA9IC0xCgogICAgICAgIG9rID0gRmFsc2UKCiAgICAgICAgd2hpbGUgb2sgaXMgbm90IFRydWU6CgogICAgICAgICAgICBjb2wgKz0gMQoKICAgICAgICAgICAgb2sgPSBUcnVlCgogICAgICAgICAgICBmb3IgayBpbiByYW5nZSggaSApOgoKICAgICAgICAgICAgICAgIGlmIG1hdHJpeFtrXVtpXSA9PSAxIGFuZCBjb2xvcnNba10gPT0gY29sOgoKICAgICAgICAgICAgICAgICAgICBvayA9IEZhbHNlCgogICAgICAgIGNvbG9yc1tpXSA9IGNvbAoKICAgIGZpbmFsX2xpc3QgPSBsaXN0KG1hcChsYW1iZGEgeDogeCsxLCBjb2xvcnMpKQoKICAgIHByaW50KGZpbmFsX2xpc3QpCgpkZWYgZm4oKToKCiAgICBtYXRyaXggPSBbWzAsMSwxLDEsMCwwLDFdLAogICAgICAgICAgICAgIFsxLDAsMSwxLDAsMCwwXSwKICAgICAgICAgICAgICBbMSwxLDAsMSwxLDAsMV0sCiAgICAgICAgICAgICAgWzEsMSwxLDAsMSwwLDFdLAogICAgICAgICAgICAgIFswLDAsMSwxLDAsMSwxXSwKICAgICAgICAgICAgICBbMCwwLDAsMCwxLDAsMV0sCiAgICAgICAgICAgICAgWzEsMCwxLDEsMSwxLDBdXQoKICAgIGNvdW50cmllcyA9IDcKCiAgICBkaXNwbGF5KG1hdHJpeCwgY291bnRyaWVzKQoKICAgIHNvbHZlKG1hdHJpeCwgY291bnRyaWVzKQoKZm4oKQo=