[백준] 13905번 - 세부 (파이썬)
# 세부 import heapq import sys input = sys.stdin.readline N, M = map(int, input().split()) start, end = map(int, input().split()) arr = [[] for _ in range(N+1)] for _ in range(M): a, b, weight = map(int, input().split()) arr[a].append((weight, b)) arr[b].append((weight, a)) visited = [0] * (N+1) def dijkstra(): q = [] heapq.heappush(q, (-sys.maxsize, start)) visited[start] = sys.maxsize while q: c..
2022. 4. 5.
[백준] 17396번 - 백도어 (파이썬)
# 백도어 import heapq import sys input = sys.stdin.readline N, M = map(int, input().split()) cant_go = list(map(int, input().split())) cant_go[-1] = 0 arr = [[]for _ in range(N)] for _ in range(M): a, b, cost = map(int, input().split()) arr[a].append((cost, b)) arr[b].append((cost, a)) dist = [sys.maxsize] * N def dijkstra(): q = [] heapq.heappush(q, (0, 0)) dist[0] = 0 while q: cost, node = heapq...
2022. 4. 2.
[백준] 5972번 - 택배 배송 (파이썬)
# 택배 배송 import heapq import sys input = sys.stdin.readline N, M = map(int, input().split()) arr = [[]for _ in range(N+1)] for _ in range(M): a, b, cost = map(int, input().split()) arr[a].append((cost, b)) arr[b].append((cost, a)) def dijkstra(): q = [] heapq.heappush(q, (0, 1)) total = [sys.maxsize] * (N+1) total[1] = 0 while q: cost, node = heapq.heappop(q) if node == N: return total[node] if t..
2022. 4. 1.