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

前端 未结 4 1693
旧巷少年郎
旧巷少年郎 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

    "For each vertex, it might point back to one of its ancestors and thus forms a cycle"

    I think it might point back to any of its ancestors which means N

    Also, how are u going to mark vertexes when you came out of its dfs, you may come there again from other vertex and its going to be another cycle. So this is not (n+m) dfs anymore.

    1. So ur algo is incomplete
    2. same here

    3. During one dfs, I think the vertex should be either unseen, or check, and for checked u can store the minimum weight for the path to the starting vertex. So if on some other stage u find an edge to that vertex u don't have to search for this path any more. This dfs will find the minimum directed cycle containing first vertex. and it's O(n^2) (O(n+m) if u store the graph as list)

    So if to do it from any other vertex its gonna be O(n^3) (O(n*(n+m))

    Sorry, for my english and I'm not good at terminology

提交回复
热议问题