Find the minimum time needed to travel from a source node to a destination node in a directed graph with weighted edges.
You are given a directed graph with n nodes labeled from 0 to n - 1. Each directed edge has a travel time. Starting from a source node, determine the minimum time required to reach a destination node.
If the destination cannot be reached, return -1.
The graph may contain multiple outgoing edges from a node, and edge times are non-negative.
Compute the smallest possible total travel time from source to destination.
n: number of nodes.edges: list of directed weighted edges, where each edge is typically represented as [u, v, w] meaning a directed edge from u to v with travel time w.source: starting node.destination: target node.Return the minimum total time to reach destination from source, or -1 if no path exists.
1 <= n0 through n - 1.Example 1
Input
n = 5, edges = [[0,1,4],[0,2,1],[2,1,2],[1,3,1],[2,3,5],[3,4,3]], source = 0, destination = 4
Output
7
Explanation
The best route is 0 -> 2 -> 1 -> 3 -> 4 with total time 1 + 2 + 1 + 3 = 7.
Example 2
Input
n = 4, edges = [[0,1,2],[1,2,2]], source = 0, destination = 3
Output
-1
Explanation
Node 3 is unreachable from node 0.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.