Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 백준 #백준2217 #백준로프 #python
- 카카오 #프로그래머스 #python #코딩테스트 #오픈채팅방
- 백준 #백준알고리즘 #알고리즘 #코딩테스트 #코딩테스트준비 #코테준비 #백준2110 #python #문제풀이
- 백준 #이거다시풀기
- 그리디알고리즘 #그리디 #백준 #우선순위큐 #최소힙 #최대힙 #알고리즘 #코딩테스트 #python
- 프로그래머스 #python #2021카카오 #카카오코테 #카카오인턴쉽
- 프로그래머스 #python #코딩테스트 #코테공부 #알고리즘 #dict
- 프로그래머스 #sql #mysql #코딩테스트
- 동
- 카카오 코테
- 프로그래머스 #c++ #코딩테스트
- 프로그래머스 #네트워크 #c++ #코딩테스트 #코테 #코테준비 #dfs
- 프로그래머스 #NULL 처리하기
Archives
- Today
- Total
say repository
[이것이 코딩테스트다] 전보 문제 본문
728x90
p263
전보 문제
# 이코테 p262
# 전보
import sys
import heapq
INF = int(1e9)
n, m, c = map(int, sys.stdin.readline().split())
graph = [[] for i in range(n+1)]
for _ in range(m):
x, y, z = map(int,sys.stdin.readline().split())
graph[x].append((y,z))
distance = [INF] * (n+1)
def dijkstra(start):
q = []
# 시작 노드로 가기위한 최단 경로 0
heapq.heappush(q, (0, start))
distance[start] = 0
while q:
dist, now = heapq.heappop(q)
if distance[now] < dist:
continue
for i in graph[now]:
y, z = i[0], i[1] #y가 노드 z가 비용
cost = dist + z
if cost < distance[y]:
distance[y] = cost
heapq.heappush(q, (cost, y))
dijkstra(c)
cnt = 0
max_distance = 0
for d in distance:
if d != INF:
cnt += 1
max_distance = max(max_distance, d)
print(cnt-1, max_distance)