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个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要 ...
随机推荐
- POJ3261 Milk Patterns(二分+后缀数组)
题目求最长的重复k次可重叠子串. 与POJ1743同理. 二分枚举ans判定是否成立 height分组,如果大于等于ans的组里的个数大于等于k-1,这个ans就可行 #include<cstd ...
- elasticsearch5.3.0 安装
公司有项目打算用elasticsearch,所以研究了下,目前最新版本5.3.0 安装 1.下载包 https://artifacts.elastic.co/downloads/elasticsea ...
- android中的开机自启动
android中的开机自启动 android中的开机自启动可分为两步: 1.写一个BroadcastReceiver: public class BootReceiver extends Broadc ...
- microsoft-sql-server release-notes
https://docs.microsoft.com/en-us/sql/release-notes/microsoft-sql-server
- shell中的cut命令
转:http://blog.sina.com.cn/s/blog_5e77c61f0100hqky.html cut是以每一行为一个处理对象的,这种机制和sed是一样的.(关于sed的入门文章将在近期 ...
- delphi怎样编译LINUX程序
delphi编译LINUX程序 DELPHI XE 10.2(TOKYO)开始可以开发LINUX控制台程序. 1)上传PASERVER到LINUX,并且运行PASERVER. 2)开始编译,PROFI ...
- BAT文件使程序具有以系统权限运行的效果
@echo off if "%1" == "h" goto begin mshta vbscript:createobject("wscript.sh ...
- 命令行设置IE代理
IE代理可以在注册表中设置,所以用DOS修改注册表,可以达到目的.方法一:注册表文件:REGEDIT4[HKEY_CURRENT_USER\Software\Microsoft\Windows\Cur ...
- UVa 156 Ananagrams(STL,map)
Ananagrams Most crossword puzzle fans are used to anagrams--groups of words with the same letters ...
- cmake 生成VS项目文件夹
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) SET_TARGET_PROPERTIES(test_tcp_client test_tcp_server P ...