single_source_shortest_path_length#

single_source_shortest_path_length(G, source, cutoff=None)[source]#

Compute the shortest path lengths from source to all reachable nodes in G.

Parameters:
GNetworkX graph
sourcenode

Starting node for path

cutoffinteger, optional

Depth to stop the search. Only paths of length <= cutoff are returned.

Returns:
lengthsdict

Dict keyed by node to shortest path length to source.

See also

shortest_path_length

Shortest path length with specifiable source, target, and weight.

single_source_dijkstra_path_length

Shortest weighted path length from source with Dijkstra algorithm.

single_source_bellman_ford_path_length

Shortest weighted path length from source with Bellman-Ford algorithm.

Examples

>>> G = nx.path_graph(5)
>>> nx.single_source_shortest_path_length(G, 0)
{0: 0, 1: 1, 2: 2, 3: 3, 4: 4}
----

Additional backends implement this function

cugraph : GPU-accelerated backend.

graphblas : OpenMP-enabled sparse linear algebra backend.