Highways - poj 2485 (Prim 算法)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 24383 | Accepted: 11243 |
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
Sample Input
1 3
0 990 692
990 0 179
692 179 0
Sample Output
692
Hint
#include <stdio.h>
#define INF 65537;
int map[][];
int vis[];
int dis[];
int n;
int Prim(){
for(int i=;i<n;i++){
vis[i]=;
dis[i]=INF;
}
dis[]=;
for(int i=;i<n;i++){
int p;
int mine=INF;
for(int j=;j<n;j++){
if(!vis[j]&&mine>dis[j]){
p=j;
mine=dis[j];
}
}
vis[p]=;
for(int j=;j<n;j++){
if(!vis[j]&&dis[j]>map[p][j])
dis[j]=map[p][j];
}
}
int maxe=;
for(int i=;i<n;i++){
if(maxe<dis[i])
maxe=dis[i];
}
return maxe;
}
int main() { int num;
scanf("%d",&num);
for(int i=;i<num;i++){
scanf("%d",&n);
for(int j=;j<n;j++){
for(int k=;k<n;k++){
scanf("%d",&map[j][k]);
}
}
int maxe=Prim();
printf("%d\n",maxe);
}
return ;
}
Highways - poj 2485 (Prim 算法)的更多相关文章
- Highways POJ-1751 最小生成树 Prim算法
Highways POJ-1751 最小生成树 Prim算法 题意 有一个N个城市M条路的无向图,给你N个城市的坐标,然后现在该无向图已经有M条边了,问你还需要添加总长为多少的边能使得该无向图连通.输 ...
- Highways POJ 2485【Prim】
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- Highways poj 2485
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- poj 2485 (kruskal算法)
/*kruskal算法*/ #include <iostream> //#include <fstream> #include <algorithm> using ...
- Agri-Net - poj 1258 (Prim 算法)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44373 Accepted: 18127 Description F ...
- Truck History - poj 1789 (Prim 算法)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20884 Accepted: 8075 Description Ad ...
- POJ 2485 Prim 找最长的边
A国没有高速公路,因此A国的交通很困难.政府意识到了这个问题并且计划建造一些高速公路,以至于可以在不离开高速公路的情况下在任意两座城镇之间行驶. A国的城镇编号为1到N, 每条高速公路连接这两个城镇, ...
- 【POJ 2485】Highways(Prim最小生成树)
题目 Prim算法:任选一个点,加入集合,找出和它最近的点,加入集合,然后用加入集合的点去更新其它点的最近距离......这题求最小生成树最大的边,于是每次更新一下最大边. #include < ...
- poj 2485 Highways (最小生成树)
链接:poj 2485 题意:输入n个城镇相互之间的距离,输出将n个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要 ...
随机推荐
- Linux的软连接和硬连接
1.Linux链接概念 Linux链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link).默认情况下,ln命令产生硬链接. [硬连接] 硬连接指通过索引 ...
- [入门OJ3876]怎样学习哲学
题目大意: 有一个$n\times m(n,m\leq 10^9)$的网格图,从一个点可以到下一行中列数比它大的点.有$k(k\leq 2000)$个点是不能走的,问从第$1$行到第$n$行共有几种方 ...
- centos安装postgresql-10及操作
安装postgresql: Linux启动: service postgresql start 创建用户: createuser username 创建数据库: createdb dbname -O ...
- [CTF]Capture The Flag -- 夺旗赛
CTF(Capture The Flag) 简单介绍 CTF(Capture The Flag)中文一般译作夺旗赛,在网络安全领域中指的是网络安全技术人员之间进行技术竞技的一种比赛形式. `In co ...
- C++中数据对齐问题。struct、union、enum,类继承。再谈sizeof()
首先是struct,在C++中,结构体其实和class有很大的相似了.但是有一点不同的是,struct默认是public,而class中是private. 当然,struct继承等用法也是可以的. 共 ...
- zend studio9.0.3破解及汉化 windons版
注册码: 34E606CF10C3E4CF202ABCEAA9B0B7A64DD2C5862A514B944AAAB38E3EB8A5F2CD735A2AB4CF9B952590EFA62BA0AB2 ...
- 关于asp.net mvc中 weiui gallery中IOS 下不显示预览图片问题的解决方式
IOS 下面不显示预览. 结果去掉了红框中的缓存部分 就可以显示了 备忘,也帮助一下需要的朋友 @*<meta http-equiv="pragma" content=&qu ...
- JSONP 安全攻防技术(JSON劫持、 XSS漏洞)
关于 JSONP JSONP 全称是 JSON with Padding ,是基于 JSON 格式的为解决跨域请求资源而产生的解决方案.他实现的基本原理是利用了 HTML 里 <script&g ...
- CSS限制
http://www.cnblogs.com/YanPSun/archive/2012/03/16/2400141.html
- [置顶]
kubernetes将外部服务映射为内部服务
在实际应用中,一般不会把mysql这种重IO.有状态的应用直接放入k8s中,而是使用专用的服务器来独立部署.而像web这种无状态应用依然会运行在k8s当中,这时web服务器要连接k8s管理之外的数据库 ...