algorithm - 关节点忽略导致直接父级的边缘的反向
问题描述
从Princeton 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;
}
解决方案
推荐阅读
- ids - Pyueye IDS相机
- algol - RESIZE 和 DEALLOCATE 对 CPU 性能的影响是什么
- javascript - discord.js 禁用“交互失败”
- ios - 从 WatchOS 获取近实时 HR 数据,无需注册数据或贡献环
- sql - 如何使用子查询创建选择子句
- python - 如何创建一个函数,通过 numpy 矩阵循环以 z 缩放每个返回标准化数据的数据点
- angular - Angular:如何处理 HMLT 模板中的嵌套 FormGroups?
- php - 将记录插入具有不同ID的mysql(按用户ID)
- python - nsolve 不断抛出 ValueError
- flutter - 你如何使颤振滑块在拇指的每一侧跟踪相同的高度?