Directed Acyclic Graph with multi-parent nodes

孤街醉人 提交于 2019-12-04 19:24:50
mickeyandkaka

It's dynamic programming.

First reverse all the edges to make a new graph, we call it newG.

  1. In newG, the node without parent has the value 0.
  2. for every node which it have parents in newG, calculate it's parent's value, then choose the minimal value parent, it must be the part of the result.
  3. when ask the path from the origin gtaph, the answer is the same in the newG.(may be the edges in the answer is in reverse order).

Time O(n)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!