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 思路:在保证不产生回 ...
随机推荐
- PHP中的错误处理
程序只要在运行,就免不了会出现错误!或早或晚,只是时间问题罢了. 错误很常见,比如Notice,Warning等等.此时一般使用set_error_handler来处理: <?php set_e ...
- EasyUI两种动态添加tab Iframe页面的方法
/** 动态添加tab-----方式一 **/ function addIframeTab(titleTxt,href,icon) { $('#mytabs').tabs('addIframeTab' ...
- hdu 1690 The Balance_母函数
题意:给你n个数,这些数可以互相加或者减,输出在范围[1,sum]里不能通过运算得出的数 思路:套母函数模版 #include <iostream> #include<cstdio& ...
- Objective-C 基本语法:实例变量与成员变量的区别.l........实例方法和类方法区别
http://leopard168.blog.163.com/blog/static/16847184420138153296930/ http://blog.csdn.net/thdxs/artic ...
- 开源 iOS 项目分类索引大全
GitHub 上大概600个开源 iOS 项目的分类和介绍,对于你挑选和使用开源项目应该有帮助 系统基础库 Category/Util sstoolkit 一套Category类型的库,附带很多自定义 ...
- 小黑小波比.coding的使用
1_Coding的演示 1_html的演示 1_先查看帮助 1.它支持的语言非常多.下面是链接地址 https://coding.net/u/bobo159357456/p/html/paas/hel ...
- XP用户:消除误解,大胆拥抱Linux
4月23日.知名家评论家Silviu Stahie发表文章.题为"Windows Users and Their Misconceptions About Linux". ...
- HTML5新特性学习-1
本文在于巩固基础 新特性:音频的使用 <!DOCTYPE html> <html> <head lang="en"> <meta char ...
- jquery选择器从认识到使用初级篇
1. .class 选择器 ---一种通过元素类别属性查找元素 调用格式: $(".class") ----其中参数表示元素的css类别名称(类选择器)<input cl ...
- UIButton 头文件常见属性和方法
UIButton头文件常见属性 1.属性 contentEdgeInsets: default is UIEdgeInsetsZero.设置内容四边距,默认边距为0 @property(nonatom ...