λ°μν
Notice
Recent Posts
Recent Comments
Link
| μΌ | μ | ν | μ | λͺ© | κΈ | ν |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- sort
- μΉ΄μΉ΄μ€
- κ·Έλν
- μλ°μ€ν¬λ¦½νΈ
- μ€ν
- μ½ν
- kakao
- μμ νμ
- Backjoon
- μΌμ±
- λ°±μ€
- λ€μ΄λλ―Ήνλ‘κ·Έλλ°
- μλ£κ΅¬μ‘°
- νλ‘κ·Έλλ¨Έμ€
- νμ΄μ¬
- SSAFY
- DFS
- Python
- algorithm
- μκ³ λ¦¬μ¦
- μΈνΌ
- νν
- SWEA
- Blind
- javascript
- boj
- BFS
- DP
- μ½λ©ν μ€νΈ
- SWμλν μ€νΈ
Archives
- Today
- Total
λ§μν
[python] λ°±μ€ - 11085. κ΅°μ¬ μ΄λ λ³Έλ¬Έ
λ°μν

π€λ¬Έμ ν΄κ²°
- ν¬λ£¨μ€μΉΌ
- Cμμ μΆλ°! κ° μ μλ κ³³μ μ°Ύμμ μ°μ μμ νμ λ£λλ€.
- μ°μ μμ νμμ λμ΄κ° κ°μ₯ λμ λ μμ λ½λλ€.
- κ±°κΈ°μ λ κ° μ μλ κ³³μ μ°Ύμμ νμ λ£λλ€. (λ¨, μ¬λ°©λ¬Έ X)
- Vλ₯Ό λ§λλ©΄ λ!
λ Έλλ₯Ό μ΄λνλ λμ μ΅μκ°μ κ³μ κ°±μ ν΄μ€λ€. (λ΅μ μ°ΎμμΌνλ―λ‘)
π»μμ€ μ½λ
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
P, W = map(int, input().split()) # Pκ°μ μ§μ , Wκ°μ κΈΈ
C, V = map(int, input().split()) # C λ°±μ€μλ, V νλΈμλ
# μΈμ λ
Έλ λ§λ€κΈ°
nodes = [input() for _ in range(W)]
adj = defaultdict(list)
for node in nodes:
a, b, c = map(int, node.split())
adj[a].append([b, c])
adj[b].append([a, c])
# μ°μ μμ ν
visited = [0] * P
pq = []
heapq.heappush(pq, [-1e9, C])
answer = 1e9 # μ΅μκ° μ°ΎκΈ°
while pq:
cur_cost, cur_node = heapq.heappop(pq)
cur_cost *= -1
if visited[cur_node]:
continue
visited[cur_node] = 1
answer = min(answer, cur_cost)
if cur_node == V:
print(answer)
break
for next_node, next_cost in adj[cur_node]:
heapq.heappush(pq, [-next_cost, next_node])
πλ¬Έμ νμΈ
μΆμ²: BACKJOON ONLINE JUDGE
λ°μν
'Algorithm Problem > Python' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
| [python] λ°±μ€ - 1347. λ―Έλ‘ λ§λ€κΈ° (0) | 2021.09.14 |
|---|---|
| [python] λ°±μ€ - 12764. μΈμ§λ°©μ κ° μ€ν (0) | 2021.09.11 |
| [python] λ°±μ€ - 19598. μ΅μ νμμ€ κ°μ (0) | 2021.09.09 |
| [python] λ°±μ€ - 1013. Contact (0) | 2021.09.08 |
| [python] λ°±μ€ - 1174. μ€μ΄λλ μ«μ (0) | 2021.09.07 |