Advertisement
nq1s788

Флойд

Apr 25th, 2024 (edited)
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. inf = float('inf')
  2. n, m = map(int, input().split())
  3. mx = [[inf for i in range(m)] for j in range(n)]
  4. for i in range(m):
  5.     x, y, w = map(int, input().split())
  6.     mx[x][y] = w
  7.     mx[y][x] = w
  8. for k in range(n):
  9.     for x in range(n):
  10.         for y in range(n):
  11.             if mx[x][y] < mx[x][k] + mx[k][y]:
  12.                 mx[x][y] = mx[x][k] + mx[k][y]
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement