61. Network Delay Time

times[i] = [u, v, w] is a directed edge from node u to node v that takes w time. A signal is sent from node k (nodes are 1..n). Return the time until all nodes receive it, or -1 if some node never does.

Example 1

Input: times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2
Output: 2

Example 2

Input: times = [[1,2,1]], n = 2, k = 1
Output: 1
Hint 1

You need the shortest time from k to every node, with positive weights: Dijkstra.

Hint 2

The answer is the largest of those shortest times.

GraphShortest PathHeap