fork download
  1. def display(matrix, countries):
  2.  
  3. for i in range(countries):
  4.  
  5. for j in range(countries):
  6.  
  7. print(matrix[i][j], end = " ")
  8. print()
  9.  
  10. def solve(matrix, countries):
  11.  
  12. colors = [0] * countries
  13.  
  14. for i in range(1, countries):
  15.  
  16. col = -1
  17.  
  18. ok = False
  19.  
  20. while ok is not True:
  21.  
  22. col += 1
  23.  
  24. ok = True
  25.  
  26. for k in range( i ):
  27.  
  28. if matrix[k][i] == 1 and colors[k] == col:
  29.  
  30. ok = False
  31.  
  32. colors[i] = col
  33.  
  34. final_list = list(map(lambda x: x+1, colors))
  35.  
  36. print(final_list)
  37.  
  38. def fn():
  39.  
  40. matrix = [[0,1,1,1,0,0,1],
  41. [1,0,1,1,0,0,0],
  42. [1,1,0,1,1,0,1],
  43. [1,1,1,0,1,0,1],
  44. [0,0,1,1,0,1,1],
  45. [0,0,0,0,1,0,1],
  46. [1,0,1,1,1,1,0]]
  47.  
  48. countries = 7
  49.  
  50. display(matrix, countries)
  51.  
  52. solve(matrix, countries)
  53.  
  54. fn()
  55.  
Success #stdin #stdout 0.04s 9512KB
stdin
Standard input is empty
stdout
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 
[1, 2, 3, 4, 1, 2, 5]