
最小生成树
文章平均质量分 69
.
ComBoat
俺好菜呀o(╥﹏╥)o
展开
-
HDU 2682 Tree(最小生成树)
Problem DescriptionThere are N (2<=N<=600) cities,each has a value of happiness,we consider two cities A and B whose value of happiness are VA and VB,if VA is a prime number,or VB is a prime number or (VA+VB) is a prime number,then they can be conne原创 2021-02-28 20:39:49 · 128 阅读 · 0 评论 -
HDU 1233 还是畅通工程
Problem Description某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。Input测试输入包含若干测试用例。每个测试用例的第1行给出村庄数目N ( < 100 );随后的N(N-1)/2行对应村庄间的距离,每行给出一对正整数,分别是两个村庄的编号,以及此两村庄间的距离。为简单起见,村庄从1到N编原创 2021-02-08 15:50:46 · 125 阅读 · 0 评论 -
POJ 1287 Networking
DescriptionYou are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect pairs of points. For each possible route between two p原创 2021-02-08 15:34:13 · 187 阅读 · 0 评论 -
POJ 1251 Jungle Roads
DescriptionThe Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to原创 2021-02-08 15:24:27 · 198 阅读 · 0 评论 -
HDU 2988 Dark roads
Problem DescriptionEconomic times these days are tough, even in Byteland. To reduce the operating costs, the government of Byteland has decided to optimize the road lighting. Till now every road was illuminated all night long, which costs 1 Bytelandian Do原创 2021-02-05 21:00:44 · 115 阅读 · 0 评论 -
HDU 3405 World Islands
Problem DescriptionDubai is a haven for the rich. The government of Dubai finds a good way to make money. They built a lot of artificial islands on the sea and sell them. These islands are shaped into the continents of the world, so they are called “world原创 2021-02-05 20:51:43 · 190 阅读 · 0 评论 -
HDU 1863 畅通工程
Problem Description省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。经过调查评估,得到的统计表中列出了有可能建设公路的若干条道路的成本。现请你编写程序,计算出全省畅通需要的最低成本。Input测试输入包含若干测试用例。每个测试用例的第1行给出评估的道路条数 N、村庄数目M ( < 100 );随后的 N 行对应村庄间道路的成本,每行给出一对正整数,分别是两个村庄的编号,以及此两村庄间道路的成本(也是正整数原创 2021-02-05 20:33:33 · 125 阅读 · 0 评论 -
最小生成树 kruskal算法
算法思路将图中的所有边都去掉将边按权值从小到大的顺序添加到图中,保证添加的过程中不会形成环重复上一步直到连接所有顶点,此时就生成了最小生成树应用了贪心思想代码代码中用了并查集,可以查看并查集#include<iostream>#include<cstdio>#include<algorithm>using namespace std;struct edge //边 { int from,to,dis;}e[200001];原创 2021-02-04 20:54:58 · 153 阅读 · 0 评论 -
最小生成树 prim算法
算法思路:首先就是从图中的一个起点a开始,把a加入U集合,然后,寻找从与a有关联的边中,权重最小的那条边并且该边的终点b在顶点集合:(V-U)中,我们也把b加入到集合U中,并且输出边(a,b)的信息,这样我们的集合U就有:{a,b},然后,我们寻找与a关联和b关联的边中,权重最小的那条边并且该边的终点在集合:(V-U)中,我们把c加入到集合U中,并且输出对应的那条边的信息,这样我们的集合U就有:{a,b,c}这三个元素了,一次类推,直到所有顶点都加入到了集合U。这里使用链式前向星进行存图 链式前向星原创 2021-02-04 20:24:00 · 118 阅读 · 0 评论