I have a directed acyclic graph (DAG). How I can find the longest path using only vertices with degree at most 2?
Currently, I try this
def all_simple_paths(g):
for path in all_paths(g):
if len(path) > 2:
center_path = path[1:-1]
nodes_degree = g.degree(center_path).values()
if max(nodes_degree) <= 2:
return path
but that might output any path, rather than the longest path.
all_paths()
is, orpath[1:-1]
.) Thank you! $\endgroup$