随笔分类 -  图论 -- 最小生成树

摘要:https://www.acwing.com/problem/content/1148/ #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie 阅读全文
posted @ 2021-02-15 17:32 phr2000 阅读(61) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1150/ 次小生成树 \(定义:给一个带权的图,把图的所有生成树按权值从小到大排序,第二小的称为次小生成树.\) 求法 \(方法1:先求最小生成树,再枚举删去最小生成树的边求解,时间复杂度\ O(mlogm + nm). 阅读全文
posted @ 2021-02-15 17:07 phr2000 阅读(62) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1145/ 思路 \(把已有的边加上,会形成各个连通块,等价于把每个连通块当成一个点去做Kruskal算法.\) #include <bits/stdc++.h> using namespace std; #define 阅读全文
posted @ 2021-02-14 23:04 phr2000 阅读(46) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1144/ #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie 阅读全文
posted @ 2021-02-14 23:01 phr2000 阅读(67) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/861/ \(裸题\) #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 1000 阅读全文
posted @ 2021-02-14 22:59 phr2000 阅读(26) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1142/ \(一道裸题\) \(最小生成树有两种算法:Prim \ 和\ Kruskal.\) \(Prim:O(n^2)\) \(Kruskal:O(mlogm)\) \(如何证明算法正确(如何证明当前这条边一定可以被 阅读全文
posted @ 2021-02-14 22:56 phr2000 阅读(51) 评论(0) 推荐(0)