Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import sys
- sys.setrecursionlimit(10000)
- # Read input
- n = int(input())
- M = []
- for i in range(n):
- row = list(map(int, input().split()))
- row = [1000000 if val < 0 else val for val in row]
- M.append(row)
- def matrixTransformation():
- for k in range(n):
- for i in range(n):
- for j in range(n):
- if i != j:
- M[i][j] = min(M[i][j], M[i][k] + M[k][j])
- matrixTransformation()
- for i in range(n):
- for j in range(n - 1):
- print(M[i][j], end=' ')
- print(M[i][n - 1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement