Skip to content

Commit

Permalink
44!
Browse files Browse the repository at this point in the history
  • Loading branch information
park-jiyeong committed Aug 13, 2024
1 parent d5c9753 commit 469dca6
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions JYPARK/41to50/44.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@

def solution(N, road, K):
answer = 0
visited = [False for _ in range(N)]
visited[0] = True
dist = {i+1: float("inf") for i in range(N)}
dist[1] = 0
q = []
graph = [[]for _ in range(N+1)]

for current_node, adjacent_node, weight in road:
graph[current_node].append((adjacent_node, weight))
graph[adjacent_node].append((current_node, weight))
for i, j, weight in road:
graph[i].append((j, weight))
graph[j].append((i, weight))

heapq.heappush(q, [1, 0]) #현재노드, 시작점에서 현재노드까지의 거리

while q:
current_node, weight = heapq.heappop(q)

if dist[current_node] < weight:
continue

for adjacent_node, new_weigth in graph[current_node]: #현재노드에 연결 돼있는 모든 노드를 볼 것임
if dist[adjacent_node] > dist[current_node] + new_weigth:
dist[adjacent_node] = dist[current_node] + new_weigth
Expand Down

0 comments on commit 469dca6

Please sign in to comment.