Skip to main content
`Ctrl`+`K`

# single_target_shortest_path

single_target_shortest_path(G, target, cutoff=None)

  Compute shortest path to target from all nodes that reach target.

  Parameters:
    G NetworkX graph
    target node label

      Target node for path

    cutoff integer, optional

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

  Returns:
    paths dictionary

      Dictionary, keyed by target, of shortest paths.

  See also

  `shortest_path`, `single_source_shortest_path`

  Notes

  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.

  Examples

      >>> G = nx.path_graph(5, create_using=nx.DiGraph())
      >>> path = nx.single_target_shortest_path(G, 4)
      >>> path[0]
      [0, 1, 2, 3, 4]