Longest path in graph

后端 未结 4 1655
一生所求
一生所求 2021-01-24 00:24

Since last 2 days,i\'m trying to find some logic for calculating longest path in graph.I know i can find it easily for DAGs and in general it is polynomial time algorithm.Formal

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-24 01:14

    You could always just use a breadth first search (BFS) and, whenever you are adding an edge to the graph you have it's cost as the additive inverse (multiply it be -1). This way you are finding the 'shortest path' by using the longest edges. Because you're doing a scalar transform, you're not losing the ability to add within the group (which you do lose if you use the multiplicative inverse).

提交回复
热议问题