Network Delay Time
Medium Advanced graphs
The nodes of a network are numbered from 1 to n. Each entry [u, v, w] of times is a one-way link: a signal at node u gets to node v w units of time later.
A signal starts from node k at time 0 and goes out along every link of every node it reaches, all at once, so each node hears it as soon as the quickest way there allows.
Return the time at which the last node hears the signal, or -1 if some node never hears it.
Example 1
The signal reaches 3 at time 2 and 4 at time 4. The link straight to 2 takes 9, but through 3 and 4 the signal arrives at 7, so 5, one more link on, hears it at 8, last of all.
Example 2
Example 3
Constraints
1 ≤ n ≤ 10⁵1 ≤ k ≤ n0 ≤ times.length ≤ 10⁵times[i] = [u, v, w], with1 ≤ u, v ≤ n,u ≠ vand0 ≤ w ≤ 10⁴- No two links go from the same node to the same node
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundMore Advanced graphs
- Course ScheduleAI round · Medium
- Cheapest Flights Within K StopsAI round · Medium
- Longest Increasing Path in a MatrixAI round · Hard
- Alien DictionaryHard
- Course Schedule IIMedium