按负边缘分割无向图

时间:2019-02-28 05:37:42

标签: graph graph-theory connected-components

想知道是否存在一种算法,可以在给定负边的情况下拆分无向的连通分量图。

基本上,在负边缘提供的顶点应该是不可达的。

1 个答案:

答案 0 :(得分:2)

如果要使图形的已连接组件仅包含正边,请首先从图形中删除所有负边。然后运行DFS(深度优先搜索)以找到所有连接的组件。

这是算法。

Begin 
    For each edge e in graph G, if e is negative, remove e from G.

    For each vertex v in G, do:
        If v is not labeled as visited
            Let c be a new component, and add c to set C.
            Call procedure DFS(v, c) to find one component of positive edges only.
        End If
    End For

    The set C contains all the connected components consisting of positive edges only.
End

Procedure DFS(v, c)
    Add v to c, and label v as visited.
    For each edge from v to w, do
        If vertex w is not labeled as visited then
            Call DFS(G,w)
        End If
    End For
End Procedure