백준 1854 : K번째 최단경로 찾기 (Python)
출처 : https://www.acmicpc.net/problem/1854 import heapq n, m, k = map(int, input().split()) graph = [[] for _ in range(n+1)] for _ in range(m) : a, b, c = map(int, input().split()) graph[a].append((c, b)) dist = [[] for _ in range(n+1)] def dijkstra(start, k) : # pq, dist에 초기값 삽입 pq = [] heapq.heappush(dist[start], 0) heapq.heappush(pq, (0, start)) while pq : # dist_now : 시작점부터 현 노드까지의 거리 dist_no..
2023. 5. 2.
백준 11779번 : 최소비용 구하기 2 (Python)
출처 : https://www.acmicpc.net/problem/11779 import heapq n = int(input()) m = int(input()) graph = [[] for _ in range(n+1)] for _ in range(m) : a, b, c = map(int, input().split()) graph[a].append((b, c)) start, end = map(int, input().split()) INF = int(1e8) dist = [[INF, 0] for _ in range(n+1)] def dijkstra(start, end) : dist[start][0] = 0 pq = [] heapq.heappush(pq, (dist[start][0], start)) while..
2023. 4. 30.