From 7aa973b561943cf30ee53b162250f0e37ad4fb0e Mon Sep 17 00:00:00 2001 From: youngyangyang04 <826123027@qq.com> Date: Sun, 6 Jul 2025 11:26:06 +0800 Subject: [PATCH] Update --- ...2.\346\216\245\351\233\250\346\260\264.md" | 3 +- ...55\344\271\260\345\234\237\345\234\260.md" | 1 - ...17\202\344\274\232dijkstra\345\240\206.md" | 1 - ...74\232dijkstra\346\234\264\347\264\240.md" | 1 - .../0053.\345\257\273\345\256\235-Kruskal.md" | 1 - .../0053.\345\257\273\345\256\235-prim.md" | 1 - ...77\346\215\242\346\225\260\345\255\227.md" | 1 - ...13\345\255\227\347\254\246\344\270\262.md" | 1 - ...8.\345\214\272\351\227\264\345\222\214.md" | 1 - ...\211\251\350\277\220\350\276\223I-SPFA.md" | 1 - ...7\347\211\251\350\277\220\350\276\223I.md" | 1 - ...\347\211\251\350\277\220\350\276\223II.md" | 101 +++++++++++++++++- ...347\211\251\350\277\220\350\276\223III.md" | 1 - ...16\351\200\233\345\205\254\345\233\255.md" | 1 - ...57\350\276\276\350\267\257\345\276\204.md" | 2 +- ...60\351\207\217\345\271\277\346\220\234.md" | 3 +- ...60\351\207\217\346\267\261\346\220\234.md" | 3 +- ...00\345\244\247\351\235\242\347\247\257.md" | 3 +- ...04\346\200\273\351\235\242\347\247\257.md" | 3 +- ...11\346\262\241\345\255\244\345\262\233.md" | 3 +- ...64\346\265\201\351\227\256\351\242\230.md" | 3 +- ...00\345\244\247\345\262\233\345\261\277.md" | 3 +- ...50\345\217\257\350\276\276\346\200\247.md" | 5 +- ...77\347\232\204\345\221\250\351\225\277.md" | 3 +- ...50\347\232\204\350\267\257\345\276\204.md" | 1 - ...27\344\275\231\350\277\236\346\216\245.md" | 1 - ...\344\275\231\350\277\236\346\216\245II.md" | 1 - ...46\344\270\262\346\216\245\351\276\231.md" | 3 +- ...57\344\273\266\346\236\204\345\273\272.md" | 1 - ...7\232\204\346\224\273\345\207\273astar.md" | 1 - ...347\224\250ACM\346\250\241\345\274\217.md" | 1 - ...06\350\256\272\345\237\272\347\241\200.md" | 1 - ...06\350\256\272\345\237\272\347\241\200.md" | 3 +- ...72\346\200\273\347\273\223\347\257\207.md" | 1 - ...06\350\256\272\345\237\272\347\241\200.md" | 3 +- ...06\350\256\272\345\237\272\347\241\200.md" | 3 +- ...30\346\200\273\347\273\223\347\257\207.md" | 1 - problems/qita/shejimoshi.md | 57 ---------- ...22\346\200\273\347\273\223\347\257\207.md" | 2 +- 39 files changed, 127 insertions(+), 100 deletions(-) delete mode 100644 problems/qita/shejimoshi.md diff --git "a/problems/0042.\346\216\245\351\233\250\346\260\264.md" "b/problems/0042.\346\216\245\351\233\250\346\260\264.md" index c208637b2f..62fbe270b7 100755 --- "a/problems/0042.\346\216\245\351\233\250\346\260\264.md" +++ "b/problems/0042.\346\216\245\351\233\250\346\260\264.md" @@ -14,8 +14,7 @@ 示例 1: - - + * 输入:height = [0,1,0,2,1,0,1,3,2,1,2,1] * 输出:6 * 解释:上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水)。 diff --git "a/problems/kamacoder/0044.\345\274\200\345\217\221\345\225\206\350\264\255\344\271\260\345\234\237\345\234\260.md" "b/problems/kamacoder/0044.\345\274\200\345\217\221\345\225\206\350\264\255\344\271\260\345\234\237\345\234\260.md" index cb5fbb7468..64804842f2 100644 --- "a/problems/kamacoder/0044.\345\274\200\345\217\221\345\225\206\350\264\255\344\271\260\345\234\237\345\234\260.md" +++ "b/problems/kamacoder/0044.\345\274\200\345\217\221\345\225\206\350\264\255\344\271\260\345\234\237\345\234\260.md" @@ -613,4 +613,3 @@ func main() { } ``` -
diff --git "a/problems/kamacoder/0047.\345\217\202\344\274\232dijkstra\345\240\206.md" "b/problems/kamacoder/0047.\345\217\202\344\274\232dijkstra\345\240\206.md" index 80d7851eaf..fceef23926 100644 --- "a/problems/kamacoder/0047.\345\217\202\344\274\232dijkstra\345\240\206.md" +++ "b/problems/kamacoder/0047.\345\217\202\344\274\232dijkstra\345\240\206.md" @@ -927,4 +927,3 @@ func main() { ### C - diff --git "a/problems/kamacoder/0047.\345\217\202\344\274\232dijkstra\346\234\264\347\264\240.md" "b/problems/kamacoder/0047.\345\217\202\344\274\232dijkstra\346\234\264\347\264\240.md" index 42099df92a..2498643a36 100644 --- "a/problems/kamacoder/0047.\345\217\202\344\274\232dijkstra\346\234\264\347\264\240.md" +++ "b/problems/kamacoder/0047.\345\217\202\344\274\232dijkstra\346\234\264\347\264\240.md" @@ -942,4 +942,3 @@ main() ### C - diff --git "a/problems/kamacoder/0053.\345\257\273\345\256\235-Kruskal.md" "b/problems/kamacoder/0053.\345\257\273\345\256\235-Kruskal.md" index 53da7af9ee..a7022c5d08 100644 --- "a/problems/kamacoder/0053.\345\257\273\345\256\235-Kruskal.md" +++ "b/problems/kamacoder/0053.\345\257\273\345\256\235-Kruskal.md" @@ -760,4 +760,3 @@ int main() } ``` - diff --git "a/problems/kamacoder/0053.\345\257\273\345\256\235-prim.md" "b/problems/kamacoder/0053.\345\257\273\345\256\235-prim.md" index df0129ee2a..d3f0aeb373 100644 --- "a/problems/kamacoder/0053.\345\257\273\345\256\235-prim.md" +++ "b/problems/kamacoder/0053.\345\257\273\345\256\235-prim.md" @@ -757,4 +757,3 @@ main() ### C - diff --git "a/problems/kamacoder/0054.\346\233\277\346\215\242\346\225\260\345\255\227.md" "b/problems/kamacoder/0054.\346\233\277\346\215\242\346\225\260\345\255\227.md" index 67d31a5564..6679f68bb6 100644 --- "a/problems/kamacoder/0054.\346\233\277\346\215\242\346\225\260\345\255\227.md" +++ "b/problems/kamacoder/0054.\346\233\277\346\215\242\346\225\260\345\255\227.md" @@ -432,4 +432,3 @@ echo $s; ### Rust: - diff --git "a/problems/kamacoder/0055.\345\217\263\346\227\213\345\255\227\347\254\246\344\270\262.md" "b/problems/kamacoder/0055.\345\217\263\346\227\213\345\255\227\347\254\246\344\270\262.md" index be998390c5..b0918f4eea 100644 --- "a/problems/kamacoder/0055.\345\217\263\346\227\213\345\255\227\347\254\246\344\270\262.md" +++ "b/problems/kamacoder/0055.\345\217\263\346\227\213\345\255\227\347\254\246\344\270\262.md" @@ -409,4 +409,3 @@ echo $s; ### Rust: - diff --git "a/problems/kamacoder/0058.\345\214\272\351\227\264\345\222\214.md" "b/problems/kamacoder/0058.\345\214\272\351\227\264\345\222\214.md" index 894e0383d5..b62adcfc62 100644 --- "a/problems/kamacoder/0058.\345\214\272\351\227\264\345\222\214.md" +++ "b/problems/kamacoder/0058.\345\214\272\351\227\264\345\222\214.md" @@ -408,4 +408,3 @@ func main() { } ``` - diff --git "a/problems/kamacoder/0094.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223I-SPFA.md" "b/problems/kamacoder/0094.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223I-SPFA.md" index 9d3fbe839e..bebc2f39c5 100644 --- "a/problems/kamacoder/0094.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223I-SPFA.md" +++ "b/problems/kamacoder/0094.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223I-SPFA.md" @@ -536,4 +536,3 @@ main() - diff --git "a/problems/kamacoder/0094.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223I.md" "b/problems/kamacoder/0094.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223I.md" index 63d1be2a30..fc79bcde1a 100644 --- "a/problems/kamacoder/0094.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223I.md" +++ "b/problems/kamacoder/0094.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223I.md" @@ -538,4 +538,3 @@ main() ### C - diff --git "a/problems/kamacoder/0095.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223II.md" "b/problems/kamacoder/0095.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223II.md" index 957b8a80bc..f9cf8151b0 100644 --- "a/problems/kamacoder/0095.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223II.md" +++ "b/problems/kamacoder/0095.\345\237\216\345\270\202\351\227\264\350\264\247\347\211\251\350\277\220\350\276\223II.md" @@ -183,7 +183,6 @@ struct Edge { //邻接表 Edge(int t, int w): to(t), val(w) {} // 构造函数 }; - int main() { int n, m, p1, p2, val; cin >> n >> m; @@ -229,16 +228,111 @@ int main() { } } } - if (flag) cout << "circle" << endl; else if (minDist[end] == INT_MAX) { cout << "unconnected" << endl; } else { cout << minDist[end] << endl; } - } +``` + +以上代码看上去没问题,但提交之后会发现报错了,为什么呢? + +例如这组数据: + +``` +4 6 +1 4 3 +1 2 1 +1 3 1 +3 2 -2 +2 4 1 +3 4 0 +``` + +如图: + + + +上面代码在执行的过程中,节点4 已经出队列了,但 计算入度会反复计算 节点4的入度,导致 误判 该图有环。 + +我们需要记录哪些节点已经出队列了,哪些节点在队列里面,对于已经出队列的节点不用统计入度,以下为优化后的代码: + +```CPP +#include参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-# 105.有向图的完全可达性 +# 105.有向图的完全联通 [卡码网题目链接(ACM模式)](https://kamacoder.com/problempage.php?pid=1177) @@ -44,6 +44,8 @@ ## 思路 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[图论:这次我们能到达有向图的所有节点吗?| 深度优先搜索 | 卡码网:105. 有向图的完全联通](https://www.bilibili.com/video/BV1QRJ6ziEvJ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 + 本题给我们是一个有向图, 意识到这是有向图很重要! 接下来我们再画一个图,从图里可以直观看出来,节点6 是 不能到达节点1 的 @@ -553,4 +555,3 @@ rl.on('close',()=>{ ### C - diff --git "a/problems/kamacoder/0106.\345\262\233\345\261\277\347\232\204\345\221\250\351\225\277.md" "b/problems/kamacoder/0106.\345\262\233\345\261\277\347\232\204\345\221\250\351\225\277.md" index 4492d5cd6d..3708715a4b 100644 --- "a/problems/kamacoder/0106.\345\262\233\345\261\277\347\232\204\345\221\250\351\225\277.md" +++ "b/problems/kamacoder/0106.\345\262\233\345\261\277\347\232\204\345\221\250\351\225\277.md" @@ -47,6 +47,8 @@ ## 思路 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[图论:这次的岛屿问题有点简单了。。 卡码网:106.岛屿的周长](https://www.bilibili.com/video/BV13fjczSEyV),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 + 岛屿问题最容易让人想到BFS或者DFS,但本题确实还用不上。 为了避免大家惯性思维,所以给大家安排了这道题目。 @@ -359,4 +361,3 @@ func parseLine(line string, count int) []int { ### C - diff --git "a/problems/kamacoder/0107.\345\257\273\346\211\276\345\255\230\345\234\250\347\232\204\350\267\257\345\276\204.md" "b/problems/kamacoder/0107.\345\257\273\346\211\276\345\255\230\345\234\250\347\232\204\350\267\257\345\276\204.md" index 9ab3388f17..572d4712e6 100644 --- "a/problems/kamacoder/0107.\345\257\273\346\211\276\345\255\230\345\234\250\347\232\204\350\267\257\345\276\204.md" +++ "b/problems/kamacoder/0107.\345\257\273\346\211\276\345\255\230\345\234\250\347\232\204\350\267\257\345\276\204.md" @@ -422,4 +422,3 @@ const isSame = (u, v) => { ### C - diff --git "a/problems/kamacoder/0108.\345\206\227\344\275\231\350\277\236\346\216\245.md" "b/problems/kamacoder/0108.\345\206\227\344\275\231\350\277\236\346\216\245.md" index de2435073c..a5076468df 100644 --- "a/problems/kamacoder/0108.\345\206\227\344\275\231\350\277\236\346\216\245.md" +++ "b/problems/kamacoder/0108.\345\206\227\344\275\231\350\277\236\346\216\245.md" @@ -376,4 +376,3 @@ const isSame = (u, v) => { ### C - diff --git "a/problems/kamacoder/0109.\345\206\227\344\275\231\350\277\236\346\216\245II.md" "b/problems/kamacoder/0109.\345\206\227\344\275\231\350\277\236\346\216\245II.md" index 6ad59c4188..fb8edbee77 100644 --- "a/problems/kamacoder/0109.\345\206\227\344\275\231\350\277\236\346\216\245II.md" +++ "b/problems/kamacoder/0109.\345\206\227\344\275\231\350\277\236\346\216\245II.md" @@ -596,4 +596,3 @@ const getRemoveEdge = (edges) => { ### C - diff --git "a/problems/kamacoder/0110.\345\255\227\347\254\246\344\270\262\346\216\245\351\276\231.md" "b/problems/kamacoder/0110.\345\255\227\347\254\246\344\270\262\346\216\245\351\276\231.md" index 6cb5886d20..facb5f21d8 100644 --- "a/problems/kamacoder/0110.\345\255\227\347\254\246\344\270\262\346\216\245\351\276\231.md" +++ "b/problems/kamacoder/0110.\345\255\227\347\254\246\344\270\262\346\216\245\351\276\231.md" @@ -63,6 +63,8 @@ yhn ## 思路 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[图论:朴实无华的广搜这么难? | 广度优先搜索 | 卡码网:110.字符串接龙](https://www.bilibili.com/video/BV1QEEizDEC4),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 + 以示例1为例,从这个图中可以看出 abc 到 def的路线 不止一条,但最短的一条路径上是4个节点。  @@ -360,4 +362,3 @@ const init = async () => { ### C - diff --git "a/problems/kamacoder/0117.\350\275\257\344\273\266\346\236\204\345\273\272.md" "b/problems/kamacoder/0117.\350\275\257\344\273\266\346\236\204\345\273\272.md" index c5650d9708..d92eede505 100644 --- "a/problems/kamacoder/0117.\350\275\257\344\273\266\346\236\204\345\273\272.md" +++ "b/problems/kamacoder/0117.\350\275\257\344\273\266\346\236\204\345\273\272.md" @@ -539,4 +539,3 @@ const init = async () => { ### C - diff --git "a/problems/kamacoder/0126.\351\252\221\345\243\253\347\232\204\346\224\273\345\207\273astar.md" "b/problems/kamacoder/0126.\351\252\221\345\243\253\347\232\204\346\224\273\345\207\273astar.md" index 6669ce7ba1..8fd331e3cd 100644 --- "a/problems/kamacoder/0126.\351\252\221\345\243\253\347\232\204\346\224\273\345\207\273astar.md" +++ "b/problems/kamacoder/0126.\351\252\221\345\243\253\347\232\204\346\224\273\345\207\273astar.md" @@ -684,4 +684,3 @@ int main() { - diff --git "a/problems/kamacoder/\345\233\276\350\256\272\344\270\272\344\273\200\344\271\210\347\224\250ACM\346\250\241\345\274\217.md" "b/problems/kamacoder/\345\233\276\350\256\272\344\270\272\344\273\200\344\271\210\347\224\250ACM\346\250\241\345\274\217.md" index c5122b1760..362ea9714a 100644 --- "a/problems/kamacoder/\345\233\276\350\256\272\344\270\272\344\273\200\344\271\210\347\224\250ACM\346\250\241\345\274\217.md" +++ "b/problems/kamacoder/\345\233\276\350\256\272\344\270\272\344\273\200\344\271\210\347\224\250ACM\346\250\241\345\274\217.md" @@ -91,4 +91,3 @@ cout << result[result.size() - 1]; 等大家将图论刷完,就会感受到我的良苦用心。加油 - diff --git "a/problems/kamacoder/\345\233\276\350\256\272\345\271\266\346\237\245\351\233\206\347\220\206\350\256\272\345\237\272\347\241\200.md" "b/problems/kamacoder/\345\233\276\350\256\272\345\271\266\346\237\245\351\233\206\347\220\206\350\256\272\345\237\272\347\241\200.md" index 61d49b5297..9566a7b7ec 100644 --- "a/problems/kamacoder/\345\233\276\350\256\272\345\271\266\346\237\245\351\233\206\347\220\206\350\256\272\345\237\272\347\241\200.md" +++ "b/problems/kamacoder/\345\233\276\350\256\272\345\271\266\346\237\245\351\233\206\347\220\206\350\256\272\345\237\272\347\241\200.md" @@ -454,4 +454,3 @@ void join(int u, int v) { 敬请期待 并查集题目精讲系列。 - diff --git "a/problems/kamacoder/\345\233\276\350\256\272\345\271\277\346\220\234\347\220\206\350\256\272\345\237\272\347\241\200.md" "b/problems/kamacoder/\345\233\276\350\256\272\345\271\277\346\220\234\347\220\206\350\256\272\345\237\272\347\241\200.md" index 718f5484a1..c76917b742 100644 --- "a/problems/kamacoder/\345\233\276\350\256\272\345\271\277\346\220\234\347\220\206\350\256\272\345\237\272\347\241\200.md" +++ "b/problems/kamacoder/\345\233\276\350\256\272\345\271\277\346\220\234\347\220\206\350\256\272\345\237\272\347\241\200.md" @@ -1,5 +1,7 @@ # 广度优先搜索理论基础 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[广度优先搜索理论基础](https://www.bilibili.com/video/BV1M19iY4EL9),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 + 在[深度优先搜索](./图论深搜理论基础.md)的讲解中,我们就讲过深度优先搜索和广度优先搜索的区别。 广搜(bfs)是一圈一圈的搜索过程,和深搜(dfs)是一条路跑到黑然后再回溯。 @@ -102,4 +104,3 @@ void bfs(vector