본문 바로가기

코딩테스트6

백준 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.
백준 24519번 : Bottleneck TSP (Large) (Python) 출처 : https://www.acmicpc.net/problem/24519 n, m = map(int, input().split()) INF = int(1e8) graph = [[INF] * n for _ in range(n)] for _ in range(m) : u, v, c = map(int, input().split()) graph[u-1][v-1] = c dp = [[0] * (1 2023. 3. 24.
백준 13701번 : 중복 제거 (Python) 출처 : https://www.acmicpc.net/problem/13701 import sys arr = bytearray(2**22) s = "" while True : c = sys.stdin.read(1) if c.isnumeric() : s += c else : n = int(s) d = n // 8 r = n % 8 if not arr[d] & (1 2023. 3. 20.