
最小生成树
HonniLin
double fighting
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
POJ 1258 - Agri-Net(最小生成树' Prim)
题目: http://poj.org/problem?id=1258 思路: 最小生成树模板题, Prim算法. CODE: #include #include #include #include using namespace std; const int INF = 0xffffff; int farm[105][105], d[105], n; bool used[105原创 2015-03-02 14:00:31 · 488 阅读 · 0 评论 -
POJ 2395 - Out of Hay(最小生成树)
题目: http://poj.org/problem?id=2395 思路: 最小生成数,WA了几遍之后去看discuss发现有重边, prim和kruskal两种算法都写了,当模板咯=.= kuskal 算法会快些. CODE: kruskal (63ms) #include #include #include using namespace std; const int原创 2015-03-02 17:37:02 · 596 阅读 · 0 评论 -
POJ 2377 - Bad Cowtractors(最小生成树)
题目: http://poj.org/problem?id=2377 思路: 最小生成树+图是否联通的判断. Kruskal: #include #include #include using namespace std; const int INF = 1e9; const int maxn = 20005; struct edge{ int u, v, cost; }原创 2015-03-09 11:24:42 · 473 阅读 · 0 评论 -
HDU 4424 - Conquer a New Region(最大生成树)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=4424 题意: n个点的树,i点到j点的路径最大价值是i到j点的路的权值最小值,以一个点为源点,使得从这个点到其他点的总价值最大。 思路: 将边权值按照从大到小排序,枚举每一条边,此时的边为当前所有边的最小边,判断将u集合合并到v集合还是 v集合合并到u集合,使用并查集实现。最后集合的祖先就是源原创 2015-09-17 16:06:34 · 573 阅读 · 0 评论