POJ 2485 Highways(最小生成树+ 输出该最小生成树里的最长的边权)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 23426 | Accepted: 10829 |
Description
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.
Input
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.
Output
each test case, you should output a line contains an integer, which is
the length of the longest road to be built such that all the villages
are connected, and this value is minimum.
Sample Input
1 3
0 990 692
990 0 179
692 179 0
Sample Output
692 代码:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#define INF 999999999
#define MIN -1
#define N 500+10 using namespace std; int map[N][N];
bool vis[N];
int dis[N];
int n, ans; void prim()
{
ans=MIN; //最小生成树的权值和初始化0
int mm;
int i, j;
memset(vis, false, sizeof(vis));
for(i=0; i<n; i++)
{
dis[i]=map[0][i];
}
vis[0]=true;
int pos;
for(i=0; i<n-1; i++)
{
mm=INF;
for(j=0; j<n; j++)
{
if(vis[j]==false && dis[j]<mm)
{
mm=dis[j];
pos=j;
}
}
if(mm>ans) ans=mm;
vis[pos]=true;
for(j=0; j<n; j++)
{
if(vis[j]==false && dis[j]>map[j][pos] )
{
dis[j]=map[j][pos];
}
}
}
printf("%d\n", ans );
} int main()
{
int i, j;
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
scanf("%d", &map[i][j] );
}
}
prim();
}
return 0;
}
POJ 2485 Highways(最小生成树+ 输出该最小生成树里的最长的边权)的更多相关文章
- poj 2485 Highways (最小生成树)
链接:poj 2485 题意:输入n个城镇相互之间的距离,输出将n个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要 ...
- poj 2485 Highways
题目连接 http://poj.org/problem?id=2485 Highways Description The island nation of Flatopia is perfectly ...
- POJ 2485 Highways【最小生成树最大权——简单模板】
链接: http://poj.org/problem?id=2485 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ 2485 Highways (求最小生成树中最大的边)
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- POJ 2485 Highways( 最小生成树)
题目链接 Description The islandnation of Flatopia is perfectly flat. Unfortunately, Flatopia has no publ ...
- POJ 2485 Highways 最小生成树 (Kruskal)
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- POJ 2485 Highways (prim最小生成树)
对于终于生成的最小生成树中最长边所连接的两点来说 不存在更短的边使得该两点以不论什么方式联通 对于本题来说 最小生成树中的最长边的边长就是使整个图联通的最长边的边长 由此可知仅仅要对给出城市所抽象出的 ...
- poj 2485 Highways 最小生成树
点击打开链接 Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19004 Accepted: 8815 ...
- poj 2485 Highways(最小生成树,基础,最大边权)
题目 //听说听木看懂之后,数据很水,我看看能不能水过 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stri ...
随机推荐
- java单例模式教程之java实现单例模式的8大方法
单例模式是Java中常用的设计模式之一.单例模式属于创建型模式,它提供了一种创建对象的最佳方式. 单例模式只创建类的一个对象,之后在一定范围为可任意调用,确保只有单个对象被创建.这个类提供了一种访问其 ...
- 转 Windows串口过滤驱动程序的开发
在Windows系统上与安全软件相关的驱动开发过程中,“过滤(filter)”是极其重要的一个概念.过滤是在不影响上层和下层接口的情况下,在Windows系统内核中加入新的层,从而不需要修改上层的软件 ...
- 【js】前台调试,在浏览器调试环境下找不到js怎么办?
针对这次 整个项目单页面的情况下,所有点击出现的新页面都是追加在母页面的情况下,很多时候不像原本的情况,可以直接在浏览器的调试环境下找到想要调试的js代码 这种情况下,怎么能找到子页面的js代码,调试 ...
- iOS -- 设置label的自适应
- (void)AutoLabel { //准备工作 self.font = [UIFont systemFontOfSize:]; self.textColor = [UIColor whiteCo ...
- mac升级系统自带numpy失败解决方案
sudo pip install -U numpy 后抛出 OSError: [Errno 1] Operation not permitted: '/tmp/pip-o2xinZ-uninstall ...
- 11gR2 RAC 独占模式replace votedisk遭遇PROC-26,restore ocr遭遇CRS-4000、PROT-35
原文链接:http://blog.itpub.net/23135684/viewspace-748816/ 11gR2 RAC系统的存储数据全然丢失,全部节点的软件都安装在本地磁盘中.本地磁盘保留了O ...
- karaf中利用Bundle引入外部log4j配置文件
环境准备: 1.在karaf_home下新建 config及logs目录 2.将mylog4j.properties拷贝到config文件夹下 查看log4j-1.2.17.jar/MANIFEST. ...
- openCV2马拉松第18圈——坐标变换
计算机视觉讨论群162501053 转载请注明:http://blog.csdn.net/abcd1992719g 收入囊中 仿射变换 坐标映射 利用坐标映射做一些效果,例如以下 watermark/ ...
- Ubuntu下安装libsvm
在安装LibSVM前需要先装 python 和 gnuplot linux 一般都自带了python2.7,所以python的安装不再赘述 在 ubuntu 下安装 gnuplot 不能直接 sudo ...
- 数据库历险记(三) | 缓存框架的连环炮 数据库历险记(二) | Redis 和 Mecached 到底哪个好? 数据库历险记(一) | MySQL这么好,为什么还有人用Oracle? 面对海量请求,缓存设计还应该考虑哪些问题?
数据库历险记(三) | 缓存框架的连环炮 文章首发于微信公众号「陈树义」,专注于 Java 技术分享的社区.点击链接扫描二维码,与500位小伙伴一起共同进步.微信公众号二维码 http://p3n ...