Find the shortest path in an undirected weighted graph.
Input
- Line 1:
n m — nodes (1 ≤ n ≤ 10^5) and edges (0 ≤ m ≤ 2·10^5)
- Next m lines:
u v w — an edge between u and v with positive weight w
- Last line:
src dst
Output
The total weight of the shortest path from src to dst, or -1 if there is none.
Hint
Dijkstra with a priority queue: always expand the closest unfinished node. Skip a popped entry when its distance is already stale — that beats trying to update entries inside the heap.
Read from standard input and write to standard output. 5 test cases in total (3 hidden). Tests for this language run inside your browser.