graph - How to find Minimum Directed Cycle (minimum total weight)?

前端 未结 4 1698
旧巷少年郎
旧巷少年郎 2020-12-13 22:06

Here is an excise:

Let G be a weighted directed graph with n vertices and m edges, where all edges have positive weight. A directed cycle is a directe

4条回答
  •  长情又很酷
    2020-12-13 22:33

    Is my algorithm correct?

    No. Let me give a counter example. Imagine you start DFS from u, there are two paths p1 and p2 from u to v and 1 path p3 from v back to u, p1 is shorter than p2.

    Assume you start by taking the p2 path to v, and walk back to u by path p3. One cycle found but apparently it's not minimum. Then you continue exploring u by taking the p1 path, but since v is fully explored, the DFS ends without finding the minimum cycle.

提交回复
热议问题