简体   繁体   English

在图形中,如何确定两个顶点是否形成桥,一旦断开桥,哪些顶点将成为哪个子图的一部分?

[英]In a graph, how do you determine if two vertices form a bridge and which vertices will be part of which subgraph once the bridge is disconnected?

I'm using an adjacency list to create my graph in C#. 我使用邻接表在C#中创建图形。

在此处输入图片说明

In this graph, #4 and #5 form a bridge that when disconnected will create two subgraphs: 在此图中,#4和#5形成了一个桥梁,当断开连接时,它将创建两个子图:

  • {1,2,3,4} {1,2,3,4}
  • {5,6,7,8} {5,6,7,8}

My question is two parts: 我的问题分为两个部分:

  1. How do I determine if #4 and #5 form a bridge? 如何确定#4和#5是否形成桥梁?
  2. How do I find out which vertices belong to which subgraph so that I can create new graphs for each of the subgraph? 如何找出哪些顶点属于哪个子图,以便可以为每个子图创建新图?

You can find all bridges in a graph in O(V+E) , read here 您可以在O(V+E)的图中找到所有桥梁, 请点击此处

After that, mark the bridges and find the connected components using DFS: 之后,标记网桥并使用DFS查找连接的组件:

for each node:
        if (not visited)
            components++
            dfs(node)

In the dfs traversal don't pass through edges that are marked as bridges. 在dfs中,遍历不要穿过标记为桥的边。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM