aryagraph.algorithms.dag.dag_longest_path#

aryagraph.algorithms.dag.dag_longest_path(g: Graph, weight: str | Callable[[Hashable, Hashable, dict], float] | None = None, default: float = 1.0) → list[Hashable][source]#

A heaviest path of a DAG, as a node list.

weight=None counts edges (so the path with the most nodes wins); an attribute name sums that edge attribute, default standing in where it is missing; a callable f(u, v, attrs) is used as is. With negative weights the best path may start anywhere, as in networkx. Ties go to the path ending earliest in topological order. O(n + m).