
最小生成树
ctsas
这个作者很懒,什么都没留下…
展开
-
最小生成树个数
在存在权值相等的边时,最小生成树可能有多个。话不多说,求它个数的方法如下:先用Prim生成最小树,同时记录边的关系。用并查集表示//不要压缩路径让每个元素都指向它的父亲节点。找出权值相同的边,去除树上的这条边,一棵树就被砍成了两颗,然后看加上另一条是否能连接这科树方法就是这样,复杂度O(|E|log|E|)具体问题:输入第一行:T //代表T组数据 每组数据:V E //代表V个顶点 E条边E原创 2017-02-02 15:49:10 · 6705 阅读 · 2 评论 -
畅通工程再续
相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现。现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题,政府决定实现百岛湖的全畅通!经过考察小组RPRush对百岛湖的情况充分了解后,决定在符合条件的小岛间建上桥,所谓符合条件,就是2个小岛之间的距离不能小于10米,也不能大于1000米。当然,为了节省资金,只要求实现任意2个小岛原创 2017-02-01 18:54:43 · 280 阅读 · 0 评论 -
Arctic Network
The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every ou原创 2017-02-01 17:30:59 · 356 阅读 · 0 评论 -
QS Network
Sunny Cup 2003 - Preliminary RoundApril 20th, 12:00 - 17:00Problem E: QS NetworkIn the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunicate with each oth原创 2017-01-31 17:47:14 · 389 阅读 · 0 评论 -
Constructing Roads
There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if th原创 2017-01-31 15:41:01 · 216 阅读 · 0 评论 -
Building a Space Station
You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task. The spac原创 2017-01-31 14:50:48 · 313 阅读 · 0 评论 -
无向图最小生成树
问题N个点M条边的无向连通图,每条边有一个权值,求该图的最小生成树。Input第1行:2个数N,M中间用空格分隔,N为点的数量,M为边的数量。(2 <= N <= 1000, 1 <= M <= 50000) 第2 - M + 1行:每行3个数S E W,分别表示M条边的2个顶点及权值。(1 <= S, E <= N,1 <= W <= 10000)Output输出最小生成树的所有边的权值之和。题原创 2017-01-31 11:51:31 · 1433 阅读 · 0 评论 -
prim 最小生成树
prim 最小生成树从单一顶点开始,普里姆算法按照以下步骤逐步扩大树中所含顶点的数目,直到遍及连通图的所有顶点。输入:一个加权连通图,其中顶点集合为V,边集合为E;初始化:Vnew = {x},其中x为集合V中的任一节点(起始点),Enew = {};重复下列操作,直到Vnew = V:在集合E中选取权值最小的边(u, v),其中u为集合Vnew中的元素,而v则是V中没有加入Vnew的顶点(原创 2017-01-30 23:24:56 · 342 阅读 · 0 评论 -
kruskal 生成最小树
kruskal 算法在排序上最费时,生成树过程复杂度是线性的,所以最终复杂度为o(|E|log|V|)。 可以对比一下prim算法 传送门》》题目链接#include<stdio.h>#include<string.h>#include<queue>#include<algorithm>#define INF 0x3f3f3f3fusing namespace std;int cos原创 2017-01-31 10:28:11 · 900 阅读 · 0 评论 -
图论算法及其模板
什么方法好,和数据关系很大,和你使用的数据结构也有关。比如使用vector,它自身就有复杂度,所以在稠密图上不及二维数组的邻接矩阵,但在稀疏图方面肯定vector的动态数组实现的链接列表更好。有些复杂度高的算法,其实际体验可能比复杂度低的更快,因为复杂度是按最糟糕的情况算的,而且复杂度低的算法往往是使用数据结构优化而实现的,而实现数据结构也是存在复杂度的,所以会出现这些个情况。原创 2017-03-01 22:04:37 · 582 阅读 · 0 评论