从普林斯顿Articulation Point的算法过程中,衔接算法dfs()忽略了指向v的边缘的反向。但是,当反向边缘指向直接父级时,为什么我们不能使用它?请参考这部分代码
// **low number - ignore reverse of edge leading to v. Why is this???**
else if (w != u)
low[v] = Math.min(low[v], pre[w]);完整的代码如下。
private void dfs(Graph G, int u, int v) {
int children = 0;
pre[v] = cnt++;
low[v] = pre[v];
for (int w : G.adj(v)) {
if (pre[w] == -1) {
children++;
dfs(G, v, w);
// update low number
low[v] = Math.min(low[v], low[w]);
// non-root of DFS is an articulation point if low[w] >= pre[v]
if (low[w] >= pre[v] && u != v)
articulation[v] = true;
}
// **low number - ignore reverse of edge leading to v. Why is this???**
else if (w != u)
low[v] = Math.min(low[v], pre[w]);
}
// root of DFS is an articulation point if it has more than 1 child
if (u == v && children > 1)
articulation[v] = true;
}https://stackoverflow.com/questions/58184233
复制相似问题