Dodomeki
Sign in

108. Network Delay

Hard

A network has n nodes numbered from 1 to n. Each directed edge [origem, destino, peso] gives the transmission time. Starting from inicio, return the minimum time needed for all reachable nodes to receive the signal, or -1 if any node cannot receive it.

Example 1
Input: n = 4, arestas = [[2,1,1],[2,3,1],[3,4,1]], inicio = 2
Output: 2
Example 2
Input: n = 2, arestas = [[1,2,7]], inicio = 1
Output: 7
Constraints
  • 1 <= n <= 100
  • 0 <= arestas.length <= 6000
  • Os pesos são inteiros positivos.
GraphsHeap
Caso 1
n =
4
arestas =
[[2,1,1],[2,3,1],[3,4,1]]
inicio =
2
Expected =
2
Caso 2
n =
2
arestas =
[[1,2,7]]
inicio =
1
Expected =
7

Run checks these 2 cases. Submit runs all 6, including hidden ones.