나의 풀이
1. 플로이드 워셜 알고리즘
n = int(input())
m = int(input())
bus = [list(map(int, input().split())) for _ in range(m)]
INF = int(1e9)
graph = [[INF] * (n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
graph[i][i] = 0
for i in bus:
if graph[i[0]][i[1]] > i[2]:
graph[i[0]][i[1]] = i[2]
for k in range(1, n + 1):
for a in range(1, n + 1):
for b in range(1, n + 1):
graph[a][b] = min(graph[a][b], graph[a][k] + graph[k][b])
for a in range(1, n + 1):
for b in range(1, n + 1):
if graph[a][b] == INF:
print(0, end = ' ')
else:
print(graph[a][b], end = ' ')
print()
for a in range(1, n + 1):
for b in range(1, n + 1):
if graph[a][b] == INF:
graph[a][b] = 0
for i in range(1, n + 1):
print(*graph[i][1:])