Skip to main content
`Ctrl`+`K`

# dag_longest_path_length

dag_longest_path_length(G, weight='weight', default_weight=1)

  Returns the longest path length in a DAG

  Parameters:
    G NetworkX DiGraph

      A directed acyclic graph (DAG)

    weight string, optional

      Edge data key to use for weight

    default_weight int, optional

      The weight of edges that do not have a weight attribute

  Returns:
    int

      Longest path length

  Raises:
    NetworkXNotImplemented

      If `G` is not directed

  See also

  `dag_longest_path`

  Examples

      >>> DG = nx.DiGraph(
      ...     [(0, 1, {"cost": 1}), (1, 2, {"cost": 1}), (0, 2, {"cost": 42})]
      ... )
      >>> list(nx.all_simple_paths(DG, 0, 2))
      [[0, 1, 2], [0, 2]]
      >>> nx.dag_longest_path_length(DG)
      2
      >>> nx.dag_longest_path_length(DG, weight="cost")
      42