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 思路:在保证不产生回 ...
随机推荐
- vs2005的MFC程序在64位机上不能运行
出现上述错误大多因为该机上没有安装vs2005程序,vs2005要运行需要一些必要的文件,没有添加到你发布的可执行文件目录下,所以程序不能运行. 解决方法: 安装目录\Microsoft Visual ...
- UI组件
1.自定义View 2.布局管理器-----ViewGroup 3.textview及其子类 4.imageview及其子类 5.adapterview及其子类----ViewGroup 6.prog ...
- logcat错误日志
http://www.crifan.com/android_log_to_file/ http://www.iteye.com/problems/85431 http://www.cnblogs.co ...
- ca 证书、签名
1.我现在没有个人CA证书,使用.中信建投网上交易,是如何保障安全的呢? 如果您目前没有个人CA证书,使用.中信建投网上交易,系统其实也是用CA证书的RSA体系进行加密的. 您在输入账户和密码进行登录 ...
- Android 获取系统内置Intent
1,掉web浏览器 Uri myBlogUri = Uri.parse("http://www.yzmanga.com"); returnIt = new Intent(Inten ...
- web站点监控脚本web_status_code,tomcat 80,oracle1521
1,完整的监控脚本如下 #!/bin/bash #web_status_code=`curl -o /dev/null -s -w "http_code:%{http_code}" ...
- Multiply Strings 大数相乘 java
先贴上代码 public String multiply(String num1, String num2) { String str = ""; StringBuffer sb ...
- ubuntu 下添加sublime text 启动图标
ubuntu下无快捷方式一说,如果想快速打开sublime Text,可以创建sublime text 启动图标 1. 创建空白文档 sublime.desktop,注意权限 $ vi /usr/sh ...
- 网站服务管理系统wdcp简介及功能特性
WDCP是WDlinux Control Panel的简称,是一套用PHP开发的Linux服务器管理系统以及虚拟主机管理系统,,旨在易于使用Linux系统做为我们的网站服务器,以及平时对Linux服务 ...
- 告示:CSDN博客通道支持Windows Live Writer写blog离线好友
尊敬的各位CSDN用户: 您好! 为了更好的服务客户.CSDN已经支持Windows Live Writer离线写博客啦.Windows Live Writer于2014年5月29日正式上线啦!欢迎大 ...