삼성 코테 준비 with 추가 알고리즘


삼성 코테 준비 with 추가 알고리즘

다익스트라(dijkstra) import heapq def dijkstra(start): distance = [float('INF')]*(N+1) distance[start] = 0 q = [] heapq.heappush((q, (distance[start], start))) while q: now_dist, now_node = heapq.heappop(q) if distance[now_node]<now_dist: continue for new_node, new_dist in graph[now_node].items(): dist = new_dist + now_dist if dist<distance[new_node]: distance[new_node] = dist heapq.heappush(q, (dist, new_node)) return distance ### N, M은 노드 수, 간선 수 T = int(input()) for tc in range(1, T+1): N, M = map...


#삼성코테준비 #알고리즘 #파이썬

원문링크 : 삼성 코테 준비 with 추가 알고리즘