可以使用哪种算法在未加权有向无环图中找到最长路径?
动态规划。鉴于它是DAG,在最长路径问题中也引用了它。
以下来自Wikipedia的代码:
algorithm dag-longest-path is input: Directed acyclic graph G output: Length of the longest path length_to = array with |V(G)| elements of type int with default value 0 for each vertex v in topOrder(G) do for each edge (v, w) in E(G) do if length_to[w] <= length_to[v] + weight(G,(v,w)) then length_to[w] = length_to[v] + weight(G, (v,w)) return max(length_to[v] for v in V(G))