有向无权图中的最长非循环路径

有向无权图中的最长非循环路径,第1张

有向无权图中的最长非循环路径

动态规划。鉴于它是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))


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5623147.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存