Highways(求最小生成树的最大边)
Highways
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 4 Accepted Submission(s) : 1
Flatopian towns are numbered from 1 to N. Each highway connects exactly two towns. All highways follow straight lines. All highways can be used in both directions. Highways can freely cross each other, but a driver can only switch between highways at a town that is located at the end of both highways.
The Flatopian government wants to minimize the length of the longest highway to be built. However, they want to guarantee that every town is highway-reachable from every other town.
The first line of each case is an integer N (3 <= N <= 500), which is the number of villages. Then come N lines, the i-th of which contains N integers, and the j-th of these N integers is the distance (the distance should be an integer within [1, 65536]) between village i and village j. There is an empty line after each test case.
#include<stdio.h>
#include<string.h>
const int INF=0x3f3f3f3f;
const int MAXN=;
#define MAX(x,y) (x>y?x:y)
int vis[MAXN],map[MAXN][MAXN],low[MAXN];
int N,answer;
void prime(){
memset(vis,,sizeof(vis));
int flot=,temp,k;
answer=-INF;
vis[]=;
for(int i=;i<=N;i++)low[i]=map[][i];
for(int i=;i<=N;i++){
temp=INF;
for(int j=;j<=N;j++)
if(!vis[j]&&temp>low[j])temp=low[k=j];
if(temp==INF){
// if(flot!=N)ans=0;
// printf("flot=%d,N=%d\n",flot,N);
break;
}
answer=MAX(answer,temp);
vis[k]=;
flot++;
for(int j=;j<=N;j++){
if(!vis[j]&&low[j]>map[k][j])low[j]=map[k][j];
}
}
}
int main(){
int T,a;
scanf("%d",&T);
while(T--){
memset(map,INF,sizeof(map));
scanf("%d",&N);
for(int i=;i<=N;i++){
for(int j=;j<=N;j++){
scanf("%d",&a);
if(j>i){
if(a<map[i][j])map[i][j]=map[j][i]=a;
}
}
}
prime();
printf("%d\n",answer);
}
return ;
}
Highways(求最小生成树的最大边)的更多相关文章
- POJ 2485 Highways (求最小生成树中最大的边)
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- POJ 2485:Highways(最小生成树&&prim)
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21628 Accepted: 9970 Descrip ...
- POJ 1751 Highways 【最小生成树 Kruskal】
Highways Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23070 Accepted: 6760 Speci ...
- POJ 2485 Highways( 最小生成树)
题目链接 Description The islandnation of Flatopia is perfectly flat. Unfortunately, Flatopia has no publ ...
- POJ 2485 Highways【最小生成树最大权——简单模板】
链接: http://poj.org/problem?id=2485 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ-1751 Highways(最小生成树消边+输出边)
http://poj.org/problem?id=1751 Description The island nation of Flatopia is perfectly flat. Unfortun ...
- (poj)1679 The Unique MST 求最小生成树是否唯一 (求次小生成树与最小生成树是否一样)
Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...
- HDU-1233 还是畅通工程 (prim 算法求最小生成树)
prim 算法求最小生成树 还是畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- prime算法求最小生成树(畅通工程再续)
连着做了四道畅通工程的题,其实都是一个套路,转化为可以求最小生成树的形式求最小生成树即可 这道题需要注意: 1:因为满足路的长度在10到1000之间才能建路,所以不满足条件的路径长度可以初始化为无穷 ...
- Kruskal和Prim算法求最小生成树
Kruskal算法求最小生成树 测试数据: 5 6 0 1 5 0 2 3 1 2 4 2 4 2 2 3 1 1 4 1 输出: 2 3 1 1 4 1 2 4 2 0 2 3 思路:在保证不产生回 ...
随机推荐
- html类,id规范命名
DIV+CSS的命名规则 SEO(搜索引擎优化)有很多工作要做,其中对代码的优化是一个很关键的步骤.为了更加符合SEO的规范,下面中部IT网将对目前流行的CSS+DIV的命名规则整理如下: 页头:he ...
- linux命令之mount
熟悉linux的同学都应该知道mount命令.在linux中,一切皆文件.硬盘分区都是以文件目录的方式存在. 如果我们想访问移动硬盘,U盘等我们必须将这些设备mount到我们linux文件系统中某个目 ...
- PHP出现Notice: unserialize() [function.unserialize]: Error at offset问题的解决方案
有两个原因(据我所知)会导致这个问题: (1) 字符串本身的问题 (2)字符编码的问题. 你unserialize的字符串的编码和文件本身的编码不一致.将文件编码改成和字符串一样的编码.这种问题比较隐 ...
- 九度OJ 题目1371:最小的K个数
题目描述: 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. 输入: 每个测试案例包括2行: 第一行为2个整数n,k(1< ...
- DevExpress VCL 2014.1.2 for C++BUILDER XE6
DevExpress VCL 2014.1.2 for C++BUILDER XE6 1)下载 DevExpress VCL 2014.1.2下载链接:http://pan.baidu.com ...
- CF#263
昨天没打,今天写了一下,前三题都没有难度吧. A. Appleman and Easy Task time limit per test 1 second memory limit per test ...
- JQuery中html()方法的注意事项
.html方法当不传参数时用来获取元素的html内容, return this[0] && this[0].nodeType === 1 ? this[0].innerHTML.rep ...
- 解决IE6下a标签的onclick事件里的超链接不跳转问题
今天遇到个很诡异的问题,就是<a href="javascript:void(0);" onclick="window.location=url"> ...
- js触摸屏案例
js 手机端触发事事件.javascript手机端/移动端触发事件 处理Touch事件能让你跟踪用户的每一根手指的位置.你可以绑定以下四种Touch事件: 1 2 3 4 touchstart: ...
- mongodb简单初级操作
学习之余记录,仅供参考 mongodb启动: mongodb安装在D:\mongodb 目录下,启动时在该目录bin文件夹下打开命令行窗口 在启动数据库时,将datapath参数指向db目录 输入 ...