poj-2485
来源:互联网 发布:诺基亚 x311玩java 编辑:程序博客网 时间:2024/05/21 09:49
Highways
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 28554 Accepted: 13022
Description
The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that it will be possible to drive between any pair of towns without leaving the highway system.
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.
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 input is an integer T, which tells how many test cases followed.
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.
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
For 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
130 990 692990 0 179692 179 0
Sample Output
692
Hint
Huge input,scanf is recommended.
Source
POJ Contest,Author:Mathematica@ZSU
题意 水题 求最小生成树的最大距离
<span style="font-size:18px;">#include<cstdio>#include<cstring>#define inf 0x3f3f3f3fint map[510][510];int dis[30000];int vis[30000];void prim(int n){int i,j;dis[1]=0;int ans=0;//最小生成树的最大距离 for(i=1;i<=n;++i){int k=-1,tp=inf;for(j=1;j<=n;++j)//找出最短距离 {if(!vis[j]&&dis[j]<tp){tp=dis[j];k=j;}}vis[k]=1;if(ans<tp){ans=tp;}for(j=1;j<=n;++j)//找出与之各个相连点的距离 {if(!vis[j]&&map[k][j]<dis[j]){dis[j]=map[k][j];} } }printf("%d\n",ans);}int main(){int t;scanf("%d",&t);while(t--){memset(dis,inf,sizeof(dis));memset(vis,0,sizeof(vis));int i,j,n;scanf("%d",&n);for(i=1;i<=n;++i){for(j=1;j<=n;++j){scanf("%d",&map[i][j]);}}prim(n);}}</span>
0 0
- poj poj 2485 Highways
- POJ 2485
- poj 2485
- POJ-2485
- poj 2485
- poj.2485
- poj-2485
- poj 2485
- poj 2485
- poj 2485
- POJ 2485
- POJ 2485
- POJ--2485
- poj-2485
- poj-2485
- poj 2485
- POJ 2485
- poj 2485
- C#开发第二天-第一个程序
- iOS之SSZipArchive压缩和解压缩
- laravel配置memcache
- 数组实现随机数并判断最大值以及位置
- POJ 1753 Flip Game
- poj-2485
- Git常用基本命令
- UVA10905 Children's Game
- 字符串反转
- # vert.x学习笔记
- HDU-2160-母猪的故事(斐波那契数列)
- 数论----概率,期望
- 如何使用狐火浏览器调试js
- Mongodb 简介