Train Ride II - Miscellaneous / Composite Patterns

The comparator declared in the solution seems to be incorrect as it will dequeue elements in descending order of the distance. It should be doing it in ascending order to be correct.

// custom comparator class for our Edge class, we want our priority queue to be in ascending order so lowest is front of the queue
public static Comparator cmp = (a, b) → b.time - a.time; // This should be a.time - b.time

Test Case #4 returns 41 as the answer because of this incorrect comparator. The correct answer should be 39.

The provided solution is sub-optimal. The trick is to view each line as a vertex in Dijkstra. Then you don’t have to select for k. You just select the cheapest line that has not been traveled yet.