Safest Route
Mediumgraphsshortest path
The world map has n towns numbered 0 to n - 1. Each entry of roads is [a, b, risk]: a two-way road between towns a and b with a non-negative danger risk. Several roads may join the same towns.
Return the smallest total danger of a route from town 0 to town n - 1, or -1 if no route exists. A route from a town to itself has danger 0.
Examples
Input: n = 4, roads = [[0,1,5],[1,3,5],[0,2,2],[2,3,9],[2,1,1]]
Output: 8
Input: n = 3, roads = [[0,1,4]]
Output: -1