241. Network Delay Time — Dijkstra

Medium · Graph

Given a network of `n` nodes labelled 1 to n and a list of travel times `times[i] = (u, v, w)`, and a source node `k`, return the minimum time for all nodes to receive the signal. Return -1 if not all nodes can be reached.

Examples

Example 1
Input: times=[[2,1,1],[2,3,1],[3,4,1]], n=4, k=2
Output: 2
Explanation: All nodes reached; slowest is node 4 at time 2

Constraints