Dijkstra’s algorithm
Find the lowest fare from one town to every other town. Add up the ticket prices along the way. Sometimes three cheap tickets cost less than one direct ticket.
Choose the cheapest unsettled vertex and try going through it to each neighbor. Road prices must be nonnegative.
Scanning the vertices for each minimum takes O(V² + E) time. A result of −1 means unreachable.