[백준] 22116번 - 창영이와 퇴근 (파이썬)
# 창영이와 퇴근 import sys import heapq N = int(input()) arr = [list(map(int, input().split())) for _ in range(N)] dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] visited = [[sys.maxsize for _ in range(N)]for _ in range(N)] def dijkstra(a, b): q = [] heapq.heappush(q, (0, a, b)) visited[a][b] = 0 while q: height, x, y = heapq.heappop(q) if visited[x][y] < height: continue for k in range(4): nx = x + dx[k] ny = ..
2022. 4. 12.
[프로그래머스] Lv2 - 배달 (파이썬)
https://programmers.co.kr/learn/courses/30/lessons/12978 코딩테스트 연습 - 배달 5 [[1,2,1],[2,3,3],[5,2,2],[1,4,2],[5,3,1],[5,4,2]] 3 4 6 [[1,2,1],[1,3,2],[2,3,2],[3,4,3],[3,5,2],[3,5,3],[5,6,1]] 4 4 programmers.co.kr import heapq import sys def solution(N, road, K): answer = 0 arr = [[]for _ in range(N+1)] for a, b, time in road: arr[a].append((time, b)) arr[b].append((time, a)) visited = [sys.maxsize] ..
2022. 4. 5.
[백준] 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.