最小生成树
文章平均质量分 83
i-unique
擅长各种姿势划水
展开
-
最小生成树之prim算法(优先队列优化)
prim算法适合稠密图,即边数较多而点较少的情况,时间复杂度为n^2,堆优化的情况下,如果点数为m,边数为n,可以达到nlongm,我还是习惯用优先队列写这个算法,思想很简单,就是每次寻找一条由已加入集合的点和与它们相邻的没加入集合的点的权值最小边(有点绕理解下),进行n-1次就找出来了,也是贪心的思想,实现就是随便找一个初始节点,然后建一个最小堆(边小的先pop出来),把该节点的vis值置为1,遍历该节点相邻的节点,如果没有被vis标记过,就加入边到堆中,扫完了以后处理堆中数据,如果弹出的边被标记过就po原创 2017-07-13 09:31:00 · 7622 阅读 · 1 评论 -
模板总结
属于自己的模板。。。比赛防忘记赛前复习向原创 2017-07-24 10:25:30 · 1551 阅读 · 1 评论 -
HDU 6187 Destroy Walls(最大生成树)
Long times ago, there are beautiful historic walls in the city. These walls divide the city into many parts of area. Since it was not convenient, the new king wants to destroy some of these walls, so he can arrive anywhere from his castle. We assume that原创 2017-09-05 19:46:42 · 482 阅读 · 0 评论 -
POJ 1861 Network(最小生成树+克鲁斯卡尔)
Andrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the company, they can be connected to each other using cables. Since each worker of the company must have access to the whole netwo原创 2017-08-17 21:16:18 · 260 阅读 · 0 评论 -
WUST 1945 局域网(最小生成树入门+克鲁斯卡尔算法)
某个局域网内有n(n<=100)台计算机,由于搭建局域网时工作人员的疏忽,现在局域网内的连接形成了回路,我们知道如果局域网形成回路那么数据将不停的在回路内传输,造成网络卡的现象。因为连接计算机的网线本身不同,所以有一些连线不是很畅通,我们用f(i,j)表示i,j之间连接的畅通程度(f(i,j)<=1000),f(i,j)值越小表示i,j之间连接越通畅,f(i,j)为0表示i,j之间无网线连接。现在我们需要解决回路问题,我们将除去一些连线,使得网络中没有回路,并且被除去网线的Σf(i,j)最大,请求出这个最大原创 2017-07-09 12:46:48 · 672 阅读 · 0 评论 -
HDU 3371 Connect the Cities (最小生成树+克鲁斯卡尔算法)
In 2100, since the sea level rise, most of the cities disappear. Though some survived cities are still connected with others, but most of them become disconnected. The government wants to build some roads to connect all of these cities again, but they don’原创 2017-07-11 19:45:34 · 365 阅读 · 0 评论 -
WUST 1946 繁忙的都市(最小生成树+克鲁斯卡尔算法)
城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造。城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条道路相连接。这些道路是双向的,且把所有的交叉路口直接或间接的连接起来了。每条道路都有一个分值,分值越小表示这个道路越繁忙,越需要进行改造。但是市政府的资金有限,市长希望进行改造的道路越少越好,于是他提出下面的要求:改造的那些道路能够把所有的交叉路口直接或间接的连通起来。在满足要求1的情况下,改造的道路尽量少。在满足原创 2017-07-15 21:20:05 · 429 阅读 · 0 评论 -
WUST 1944 最短网络Agri-Net(最小生成树之prim算法)
农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场。当然,他需要你的帮助。约翰已经给他的农场安排了一条高速的网络线路,他想把这条线路共享给其他农场。为了用最小的消费,他想铺设最短的光纤去连接所有的农场。你将得到一份各农场之间连接费用的列表,你必须找出能连接所有农场并所用光纤最短的方案。每两个农场间的距离不会超过100000。原创 2017-07-15 19:58:03 · 434 阅读 · 0 评论 -
WUST 1947 联络员(最小生成树+部分连好的点)
Tyvj已经一岁了,网站也由最初的几个用户增加到了上万个用户,随着Tyvj网站的逐步壮大,管理员的数目也越来越多,现在你身为Tyvj管理层的联络员,希望你找到一些通信渠道,使得管理员两两都可以联络(直接或者是间接都可以)。Tyvj是一个公益性的网站,没有过多的利润,所以你要尽可能的使费用少才可以。 目前你已经知道,Tyvj的通信渠道分为两大类,一类是必选通信渠道,无论价格多少,你都需要把所有的都选择上;还有一类是选择性的通信渠道,你可以从中挑选一些作为最终管理员联络的通信渠道。数据保证给出的通行渠道可以原创 2017-07-16 08:44:41 · 524 阅读 · 0 评论 -
HDU 1301 Jungle Roads(最小生成树+克鲁斯卡尔算法)
The 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 maintain. Th原创 2017-07-27 18:47:15 · 542 阅读 · 0 评论 -
POJ 2395 Out of Hay(最小生成树+克鲁斯卡尔)
The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms to survey their hay situation. There are N (2 <= N <= 2,000) farms (numbered 1..N); Bessie starts at Farm 1. She'll traverse some or a原创 2017-08-01 15:46:16 · 332 阅读 · 0 评论 -
POJ 3522 Slim Span(生成树+克鲁斯卡尔)
Given an undirected weighted graph G, you should find one of spanning trees specified as follows.The graph G is an ordered pair (V, E), where V is a set of vertices {v1, v2, …, vn} and E is a set of undirected edges {e1, e2, …, em}. Each edge e ∈ E has it原创 2017-08-08 18:56:06 · 403 阅读 · 0 评论 -
CodeForces125E MST Company(根限度为k的最小生成树+二分)
The MST (Meaningless State Team) company won another tender for an important state reform in Berland.There are n cities in Berland, some pairs of the cities are connected by roads. Each road has its price. One can move along any road in any direction. The原创 2017-09-03 15:25:37 · 953 阅读 · 0 评论