Skip to content

Commit

Permalink
Merge pull request #36 from AlgoLeadMe/10-suhyun113
Browse files Browse the repository at this point in the history
10-suhyun113
  • Loading branch information
suhyun113 authored Jul 24, 2024
2 parents 4979c92 + 42c996d commit d4f81c0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion suhyun113/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
| 6μ°¨μ‹œ | 2024.04.14 | μŠ€νƒ | [컨트둀 제트](https://school.programmers.co.kr/learn/courses/30/lessons/120853) | [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/21) |
| 7μ°¨μ‹œ | 2024.05.09 | 트리 | [μ›μˆ­μ΄ 맀달기](https://www.acmicpc.net/problem/2716) | [#31](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/31) |
| 8μ°¨μ‹œ | 2024.05.14 | μˆ˜ν•™ | [μ–΄λ¦° μ™•μž](https://www.acmicpc.net/problem/1004) | [#32](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/32) |
| 9μ°¨μ‹œ | 2024.05.28 | λ‹€μ΅μŠ€νŠΈλΌ | [μ΅œμ†ŒλΉ„μš© κ΅¬ν•˜κΈ°](https://www.acmicpc.net/problem/1916) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/33) |
| 9μ°¨μ‹œ | 2024.05.28 | λ‹€μ΅μŠ€νŠΈλΌ | [μ΅œμ†ŒλΉ„μš© κ΅¬ν•˜κΈ°](https://www.acmicpc.net/problem/1916) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/33) |
| 10μ°¨μ‹œ | 2024.07.13 | ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ | [ν”Œλ‘œμ΄λ“œ](https://www.acmicpc.net/problem/11404) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/36) |
41 changes: 41 additions & 0 deletions suhyun113/ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ/10-suhyun113.py
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()

0 comments on commit d4f81c0

Please sign in to comment.