-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from AlgoLeadMe/10-suhyun113
10-suhyun113
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 11404 : νλ‘μ΄λ | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
INF = float('inf') # μ΅λκ° μ μ | ||
|
||
# λ Έλμ κ°μ(n)κ³Ό κ°μ μ κ°μ(m) μ λ ₯ | ||
n = int(input()) # λμμ κ°μ n | ||
m = int(input()) # λ²μ€μ κ°μ m | ||
|
||
# 2μ°¨μ 리μ€νΈ (κ·Έλν νν) λ§λ€κ³ , 무νλλ‘ μ΄κΈ°ν(νλ‘μ΄λ-μμ = μ΄μ°¨μ λ°°μ΄) | ||
graph = [[INF] * (n + 1) for _ in range(n + 1)] | ||
|
||
# iμμ jλ‘ κ° μ μλ κ²½μ°, | ||
# μκΈ° μμ μμ μκΈ° μμ μΌλ‘ κ°λ λΉμ©μ 0μΌλ‘ μ΄κΈ°ν(λκ°μ μ ν΄λΉνλ λΆλΆ)) | ||
for i in range(1, n + 1): | ||
for j in range(1, n + 1): | ||
if i == j: | ||
graph[i][j] = 0 | ||
|
||
# κ° κ°μ μ λν μ 보λ₯Ό μ λ ₯λ°μ, κ·Έ κ°μΌλ‘ μ΄κΈ°ν | ||
for _ in range(m): | ||
# A -> Bλ‘ κ°λ λΉμ©μ CλΌκ³ μ€μ | ||
i, j, cost = map(int, input().split()) | ||
if graph[i][j] > cost: # μμ λμμ λμ°© λμ μ°κ²°νλ λ Έμ νλκ° x | ||
graph[i][j] = cost | ||
|
||
# μ νμμ λ°λΌ νλ‘μ΄λ μμ μκ³ λ¦¬μ¦μ μν(3μ€ forλ¬Έ) | ||
for k in range(1, n + 1): | ||
for i in range(1, n + 1): | ||
for j in range(1, n + 1): | ||
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]) | ||
|
||
# μνλ κ²°κ³Όλ₯Ό μΆλ ₯ | ||
for i in range(1, n + 1): | ||
for j in range(1, n + 1): | ||
if graph[i][j] == INF: | ||
print(0, end=' ') | ||
else: | ||
print(graph[i][j], end=' ') | ||
print() |