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",…
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…
题意: 有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[…
修路 时限: 2000MS   内存限制: 65536K 提交总数: 31810   接受: 14215 描述 有N个村庄,编号从1到N,您应该修建一些道路,使每两个村庄可以相互连接.我们说两个村庄A和B是连通的,当且仅当A和B之间有一条道路,或者存在一个村庄C使得A和C之间有一条道路,并且C和B连通时. 我们知道,一些村庄之间已经存在一些道路,您的工作是建造一些道路,以使所有村庄都连接起来,并且所有道路的长度都应最小. 输入 第一行是整数N(3 <= N <= 100),它是村庄的数量.然后…
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://poj.org/problem?id=2421 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 21130   Accepted: 8924 Description There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can…
Constructing Roads 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 betw…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 题意:这道题实际上和hdu 1242 Rescue 非常相似,改变了输入方式之后, 本题实际上更适合用Prim来做. 用Kruscal的话要做一些变化. /*Constructing Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s)…
Constructing Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/D 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 villa…