This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
single_source_shortest_path(G, source, cutoff=None)¶
Compute shortest path between source and all other nodes reachable from source.
G : NetworkX graph
source : node label
Starting node for path
cutoff : integer, optional
Depth to stop the search. Only paths of length <= cutoff are returned.
lengths : dictionary
Dictionary, keyed by target, of shortest paths.
The shortest path is not necessarily unique. So there can be multiple paths between the source and each target node, all of which have the same ‘shortest’ length. For each target node, this function returns only one of those paths.
>>> G=nx.path_graph(5) >>> path=nx.single_source_shortest_path(G,0) >>> path [0, 1, 2, 3, 4]