There are n bus stops, and we know the fee between the i-th and j-th stops. This is a one-way road. What is the minimum price of the route from the 1st to the n-th stop, taking into account all possible connections? The consumption of time and memory should be the least possible.
ps For example, there are 4 stops. We have such a price table:
. 3 $ 5 $ 7 $
. . 1 $ 3 $
. . . 1 $
go from 1st to 4th, non-stop we pay $ 7. if we change routes at the second stop, we pay $ 3 + $ 1 = $ 4 to get to the third stop, but we pay $ 2 more if we go to the end, so in general it will cost $ 6, but again however, if we change routes at the 3rd stop, we will pay 4 + 1 = $ 5.
source
share