-
[백준 문제풀이] 얼렁뚱땅 1916 최소비용 구하기 풀이얼렁뚱땅 백준 문제풀이 2022. 9. 22. 16:54
https://www.acmicpc.net/problem/1916
1916번: 최소비용 구하기
첫째 줄에 도시의 개수 N(1 ≤ N ≤ 1,000)이 주어지고 둘째 줄에는 버스의 개수 M(1 ≤ M ≤ 100,000)이 주어진다. 그리고 셋째 줄부터 M+2줄까지 다음과 같은 버스의 정보가 주어진다. 먼저 처음에는 그
www.acmicpc.net
from collections import deque n = int(input()) m = int(input()) dict_ = {} visited = [100000001]*(n+1) for i in range(m) : start, end, money = map(int,input().split()) if start not in dict_ : dict_[start] = [[end,money]] else : dict_[start].append([end,money]) want_start, want_end = map(int,input().split()) q = deque() q.append([want_start,0]) while q : start, money = q.popleft() if visited[start] != want_start and visited[start] < money : continue if start not in dict_ : continue for i in range(len(dict_[start])) : if money + dict_[start][i][1] < visited[dict_[start][i][0]] : q.append([dict_[start][i][0],money + dict_[start][i][1]]) visited[dict_[start][i][0]] = money + dict_[start][i][1] print(visited[want_end])
'얼렁뚱땅 백준 문제풀이' 카테고리의 다른 글
[백준 문제풀이] 얼렁뚱땅 15666번 N과 M(12) 풀이 (0) 2022.09.24 [백준 문제풀이] 얼렁뚱땅 20055 컨베이어 벨트 위의 로봇 풀이 (1) 2022.09.23 [백준 문제풀이] 얼렁뚱땅 3184 양 풀이 (4) 2022.09.21 [백준 문제풀이] 얼렁뚱땅 2589 보물섬 풀이 (0) 2022.09.20 [백준 문제풀이] 얼렁뚱땅 1138 한 줄로 서기 풀이 (0) 2022.09.20