Advertisement
SetKaung

matt

Oct 2nd, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. import time
  2. import sys
  3. sys.setrecursionlimit(10000)
  4.  
  5. # Read input
  6. n = int(input())
  7. M = []
  8.  
  9. for i in range(n):
  10.     row = list(map(int, input().split()))
  11.     row = [1000000 if val < 0 else val for val in row]
  12.     M.append(row)
  13.  
  14. def matrixTransformation():
  15.     for k in range(n):
  16.         for i in range(n):
  17.             for j in range(n):  
  18.                 if i != j:
  19.                     M[i][j] = min(M[i][j], M[i][k] + M[k][j])
  20.  
  21. matrixTransformation()
  22.  
  23.  
  24. for i in range(n):
  25.     for j in range(n - 1):
  26.         print(M[i][j], end=' ')
  27.     print(M[i][n - 1])
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement