⬅ Previous Topic
Shortest Path in Undirected Graph with Unit DistanceNodes | Edges | Output | Description |
---|---|---|---|
6 | [[0,1,2],[0,4,1],[1,2,3],[4,2,2],[2,3,6],[4,5,4],[5,3,1]] | [0,2,3,6,1,5] | Shortest paths from node 0 using topological order and edge relaxation |
3 | [[0,1,5],[1,2,3]] | [0,5,8] | Path 0 → 1 → 2 accumulates weight |
4 | [[0,1,1],[0,2,4],[1,3,2],[2,3,1]] | [0,1,4,3] | Shortest path from 0 to 3 is via node 2 |
1 | [] | [0] | Single node, no edges |
3 | [[1,2,1]] | [0, ∞, ∞] | No outgoing edges from source 0 |