반응형
1446번: 지름길
첫째 줄에 지름길의 개수 N과 고속도로의 길이 D가 주어진다. N은 12 이하인 양의 정수이고, D는 10,000보다 작거나 같은 자연수이다. 다음 N개의 줄에 지름길의 시작 위치, 도착 위치, 지름길의 길이
www.acmicpc.net
코드
n, d = map(int,input().split())
n_list = [list(map(int,input().split())) for _ in range(n)]
graph = [i for i in range(d+1)]
for i in range(d+1):
graph[i] = min(graph[i],graph[i-1]+1)
for start,end,le in n_list:
if i == start and end <= d:
graph[end] = min(graph[end],graph[i]+le)
print(graph[-1])
반응형
'알고리즘 > 그래프 탐색' 카테고리의 다른 글
[백준][Python] 1743번 음식물 피하기 (0) | 2022.12.20 |
---|---|
[백준][Python] 2583번 영역 구하기 (0) | 2022.12.01 |
[백준][Python] 10026번 적록색약 (0) | 2022.11.29 |
[백준][Python] 14502번 연구소 (0) | 2022.11.09 |
[백준][Python] 1697번 숨바꼭질 (0) | 2022.10.26 |
댓글