The signal travels to all nodes simultaneously. The time it takes for node to get the signal is the shortest path from to . Run Dijkstra from source . Find dist[x] for all nodes.
The answer is max(dist[x]) over all . If any dist[x] = Infinity, return . This problem is direct Dijkstra application. No tricks, implement it correctly. Good for practice. Watch out for -indexed vs -indexed node numbering in the input.