1192. Critical Connections in a Network
Question
There are
n
servers numbered from0
ton - 1
connected by undirected server-to-serverconnections
forming a network whereconnections[i] = [a<sub>i</sub>, b<sub>i</sub>]
represents a connection between serversa<sub>i</sub>
andb<sub>i</sub>
. Any server can reach other servers directly or indirectly through the network.A critical connection is a connection that, if removed, will make some servers unable to reach some other server.
Return all critical connections in the network in any order.
Solution
根据connections建立图(采用数组记录图速度比用哈希表实现快)。
然后采用Tarjon算法寻找图中的桥。
时间戳
按访问顺序为数组dfn[]添加顺序。
(dfn = depth first (traversal) number)
搜索树
在无向图中,每一次从u节点出发进行DFS搜索,每个节点只访问一次,所有被访问过的节点与边构成一棵树,称之为“无向连通图的搜索树”
追溯值
数组low[]记录从当前节点u出发时,能够访问到的所有节点中,时间戳最小的值。
无向图的桥的判定法则
在一张无向图中,判断边 e (其对应的两个节点分别为 u 与 v)是否为桥,需要其满足如下条件即可:dfn[u] < low[v]
Code
1 | class Solution { |
1192. Critical Connections in a Network
https://xuanhe95.github.io/2022/05/18/1192-Critical-Connections-in-a-Network/