[英]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形成了一个桥梁,当断开连接时,它将创建两个子图:
My question is two parts: 我的问题分为两个部分:
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.