Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions froglike6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
| 4์ฐจ์‹œ | 2025.03.30 | ๊ทธ๋ž˜ํ”„ | [์นœ๊ตฌ](https://www.acmicpc.net/problem/1058)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/16|
| 5์ฐจ์‹œ | 2025.04.01 | ์ •์ˆ˜ | [๊ฐœ๊ตฌ๋ฆฌ](https://www.acmicpc.net/problem/25333)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/17|
| 6์ฐจ์‹œ | 2025.04.07 | ๋ฐฑํŠธ๋ž˜ํ‚น| [N-Queen](https://www.acmicpc.net/problem/9663)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/24|
| 7์ฐจ์‹œ | 2025.04.09 | ๊ทธ๋ž˜ํ”„ | [์ตœ์†Œ๋น„์šฉ ๊ตฌํ•˜๊ธฐ](https://www.acmicpc.net/problem/1916)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/27|
---
30 changes: 30 additions & 0 deletions froglike6/graph_theory/1916.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
import heapq

def dijkstra(n, graph, start):
INF = float('inf')
distances = [INF] * (n + 1)
distances[start] = 0
queue = [(0, start)]

while queue:
current_cost, current_node = heapq.heappop(queue)
if current_cost > distances[current_node]:
continue
for next_node, weight in graph[current_node]:
cost = current_cost + weight
if cost < distances[next_node]:
distances[next_node] = cost
heapq.heappush(queue, (cost, next_node))
return distances

input = sys.stdin.readline
N = int(input())
M = int(input())
graph = [[] for _ in range(N+1)]
for _ in range(M):
u, v, w = map(int, input().split())
graph[u].append((v, w))
start, end = map(int, input().split())
distances = dijkstra(N, graph, start)
print(distances[end])