修路 时限: 2000MS   内存限制: 65536K 提交总数: 31810   接受: 14215 描述 有N个村庄,编号从1到N,您应该修建一些道路,使每两个村庄可以相互连接.我们说两个村庄A和B是连通的,当且仅当A和B之间有一条道路,或者存在一个村庄C使得A和C之间有一条道路,并且C和B连通时. 我们知道,一些村庄之间已经存在一些道路,您的工作是建造一些道路,以使所有村庄都连接起来,并且所有道路的长度都应最小. 输入 第一行是整数N(3 <= N <= 100),它是村庄的数量.然后…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1102 /************************************************************************/ /* hdu Constructing Roads 最小生成树 题目大意:在N个村子中已经存在部分存在连通,建最少长度的路使得所有的村子连通. 解题思路:已经连通的村子其中间的路径作为0,即修建的时候修建为0耗费,求这些节点的最小生成树. */ /*…
最小生成树模板(嗯……在kuangbin模板里面抄的……) 最小生成树(prim) /** Prim求MST * 耗费矩阵cost[][],标号从0开始,0~n-1 * 返回最小生成树的权值,返回-1表示原图不连通 */ const int INF = 0x3f3f3f3f; const int MAXN = 110; bool vis[MAXN]; int lowc[MAXN]; int map[MAXN][MAXN]; int Prim(int cost[][MAXN], int n) {…
Constructing Roads Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 54   Accepted Submission(s) : 28 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description There are N villag…
Constructing Roads 这道题很水,就是一个裸的最小生成树,最不过把已经连接的节点的值再设为0. 代码: #include<cstdio> #include<cstring> #define N 1010 int dis[N][N],minn[N],n,m,a,b; bool u[N]; int main(){ scanf("%d",&n); ;i<=n;++i) ;j<=n;++j) scanf("%d",…
Constructing Roads Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2421 Appoint description:  System Crawler  (2015-05-27) Description There are N villages, which are numbered from 1 to N, and y…
题意: 有N个点,有些点已经连接了,然后求出所有点的连接的最短路径是多少. 思路: 最小生成树的变形,有的点已经连接了,就直接把他们的权值赋为0,一样的就做最小生成树. 代码: prime: #include <cstdio> #include <iostream> using namespace std; #define maxn 100+5 #define inf 0x3f3f3f3f int maps[maxn][maxn]; bool vis[maxn]; int dis[…
SB题,求最小生成树,其中有些边已经给您建好啦. 随意暴力即可. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ],fa[],n,m,a[][],q,x,y,f1,f2,ans; ;i<=n;i++) fa[i]=i;} int findroot(int x) { if(fa[x]==x) return x; int rt=findroot(fa[x]); f…
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 there exists a…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 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 conne…