문제
https://www.acmicpc.net/problem/11404
풀이
floyd 알고리즘
소스코드
n = int(input())
m = int(input())
arr = [[1e9]*(n+1) for _ in range(n+1)]
for i in range(1, n+1):
for j in range(1, n+1):
if i == j:
arr[i][j] = 0
for _ in range(m):
i, j, cost = map(int, input().split())
arr[i][j] = min(arr[i][j], cost)
for k in range(1 ,n+1):
for i in range(1, n+1):
for j in range(1, n+1):
arr[i][j] = min(arr[i][j], arr[i][k] + arr[k][j])
for i in range(1, n+1):
for j in range(1, n+1):
if arr[i][j] == 1e9:
arr[i][j] = 0
print(arr[i][j], end= ' ')
print()
'💡Problem Solving > BOJ' 카테고리의 다른 글
[BOJ 2887] 행성 터널 (Python) (0) | 2022.11.23 |
---|---|
[BOJ 18353] 병사 배치하기 (Python) (0) | 2022.11.22 |
[BOJ 1715] 카드 정렬하기 (Python) (0) | 2022.11.19 |
[BOJ 18310] 안테나 (Python) (0) | 2022.11.19 |
[BOJ 10825] 국영수 (Python) (0) | 2022.11.19 |