Given a connected undirected graph, tell if its minimum spanning tree is unique.
Definition 1 (Spanning Tree): Consider a connected, undirected graph G = (V, E). A spanning tree of G is a subgraph of G, say T = (V', E'), with the following properties:
1...
分类:
其他好文 时间:
2015-02-23 15:33:46
阅读次数:
257
Problem Description
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 there is a road between A and B, or t...
分类:
编程语言 时间:
2015-02-23 15:31:07
阅读次数:
231
Problem Description
Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result it can ...
分类:
编程语言 时间:
2015-02-23 09:45:09
阅读次数:
333
During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu, Yan, Han, Zhao, Wei and Qin. Ying Zheng was the king of the kingdom Qin. Through 9 years of wars, he finally conquered all six o...
分类:
编程语言 时间:
2015-02-23 09:42:05
阅读次数:
254
prim算法描述:prim算法的思想和代码都跟dijkstra算法非常相似。在dijkstra算法中,我们用每次取出未标记集合中到源点最近的点进行标记并更新其邻接点到源点的距离:当d[x]+w 2 #include 3 #include 4 5 using namespace std; 6 ...
分类:
编程语言 时间:
2015-02-22 21:53:54
阅读次数:
152
Problem Description
省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。经过调查评估,得到的统计表中列出了有可能建设公路的若干条道路的成本。现请你编写程序,计算出全省畅通需要的最低成本。
Input
测试输入包含若干测试用例。每个测试用例的第1行给出评估的道路条数 N、村庄数目M ( < 100 );随后的 N
行对应村庄间道路的成本,每行给出一对正整数,分别是两个村庄的编号,以及此两村庄间道路的成本(也是正整...
分类:
编程语言 时间:
2015-02-22 14:39:44
阅读次数:
210
Problem Description
省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。现得到城镇道路统计表,表中列出了任意两城镇间修建道路的费用,以及该道路是否已经修通的状态。现请你编写程序,计算出全省畅通需要的最低成本。
Input
测试输入包含若干测试用例。每个测试用例的第1行给出村庄数目N ( 1< N < 100 );随后的 N(N-1)/2 行对应村庄间道路的成本及修建状态,每行给4个正整数,分别是两个村庄的编号(从...
分类:
其他好文 时间:
2015-02-22 11:05:47
阅读次数:
122
只要把prim算法稍微改一下就可以了。
#include
#include
#include
#include
using namespace std;
const int N=505;
const int inf=1<<28;
int cost[N][N],mincost[N];
bool used[N];
int n;
int prim()
{
int _max=0;...
分类:
其他好文 时间:
2015-02-15 16:36:39
阅读次数:
182
原文:http://www.cnblogs.com/Veegin/archive/2011/04/29/2032388.html注:这篇博文思路清晰,代码简洁,非常值得学习,特此mark今天从志权师兄那里学会了最小生成树。所谓生成树,就是n个点之间连成n-1条边的图形。而最小生成树,就是权值(两点间...
分类:
编程语言 时间:
2015-02-14 17:26:08
阅读次数:
212
在边赋权图中,权值总和最小的生成树称为最小生成树。构造最小生成树有两种算法,分别是prim算法和kruskal算法。在边赋权图中,如下图所示: 在上述赋权图中,可以看到图的顶点编号和顶点之间邻接边的权值,若要以...
分类:
编程语言 时间:
2015-02-14 07:39:16
阅读次数:
215