# @param {Integer} n
# @param {Integer[][]} flights
# @param {Integer} src
# @param {Integer} dst
# @param {Integer} k
# @return {Integer}
def find_cheapest_price(n, flights, src, dst, k)
inf=1<<128
min_dist=[inf]*n
min_dist[src]=0
(k+1).times do
mdp=min_dist.dup
flights.each do|i,j,v|
mdp[j]=[min_dist[i]+v,mdp[j]].min
end
min_dist=mdp.dup
end
ddist=min_dist[dst]
return -1 if ddist>=inf
ddist
end
787. Cheapest Flights Within K Stops
chromat..(hjroh0315)
2023-01-26 11:48
추천 0
다른 게시글
-
2359. Find Closest Node to Given Two Nod이벤트(219.251) | 23.01.26추천 0
-
2359. Find Closest Node to Given Two ~ [1]개발뉴비(coderhs) | 23.01.26추천 0
-
이벤트 너무 어려운데 힌트 봐도 되나요 [1]이벤트(39.7) | 23.01.25추천 0
-
2359. Find Closest Node to Given Two Nodchromate00(hjroh0315) | 23.01.25추천 0
-
53. Maximum Subarray크아아아앙(rkxszkumymda) | 23.01.25추천 0
-
45. Jump Game II크아아아앙(rkxszkumymda) | 23.01.25추천 0
-
55. Jump Game크아아아앙(rkxszkumymda) | 23.01.25추천 0
-
909. Snake and Ladderschromate00(hjroh0315) | 23.01.24추천 0
-
909. Snakes and Ladders [1]개발뉴비(coderhs) | 23.01.24추천 0
-
909. Snakes and Ladders이벤트ㅇㅅ..(219.251) | 23.01.24추천 0
댓글 0