poj 2485 Highways
来源:互联网 发布:网络诈骗案件2017 编辑:程序博客网 时间:2024/06/05 11:31
Highways
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 27678 Accepted: 12645
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
最小生成树,但是要稍微修改一下输出,不是输出最小生成树的总长度,而是输出最小生成树中最大的边;
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <vector>using namespace std;const int inf=0x3f3f3f3f;int maze[501][501];int dis[501];bool vis[501];int prim(int cnt){ memset(vis,0,sizeof(vis)); memset(dis,inf,sizeof(dis)); int ans=0; for(int i=1;i<=cnt;++i) { dis[i]=maze[1][i]; } vis[1]=1; for(int i=1;i<=cnt-1;++i) { int flag,zmin=inf; for(int j=1;j<=cnt;++j) { if(!vis[j]&&dis[j]<zmin) { flag=j; zmin=dis[j]; } } vis[flag]=1; ans=max(zmin,ans); for(int j=1;j<=cnt;++j) { if(!vis[j]&&dis[j]>maze[flag][j]) { dis[j]=maze[flag][j]; } } } return ans;}int main(){ int T; scanf("%d",&T); while(T--) { int N; scanf("%d",&N); for(int i=1;i<=N;++i) for(int j=1;j<=N;++j) { scanf(" %d",&maze[i][j]); } int ans=prim(N); printf("%d\n",ans); } return 0;}
0 0
- poj poj 2485 Highways
- POJ 2485 Highways
- poj 2485 Highways
- POJ-2485 highways
- POJ 2485 Highways Kruskal
- poj 2485 Highways
- Poj 2485 Highways
- POJ 2485 Highways
- poj 2485 Highways
- poj 2485 Highways
- POJ 2485 Highways
- POJ 2485 Highways
- POJ 2485 Highways
- POJ 2485 Highways
- Poj 2485 Highways
- poj 2485 Highways
- poj 2485 highways
- POJ 2485 Highways
- java异常中Exception捕获不到的异常
- Horizontalscroll自定义编辑横向滑动的位置,
- [Linux] Nutch 2.3.1+ Hbase + Hadoop + Solr 单机指南(一)
- 关于jar包add to build path与放入lib下的区别
- HTML常用鼠标指针样式设置
- poj 2485 Highways
- JAXB学习一 (入门)JAXB学习二 (类型绑定)
- Java EE中Servlet的内置对象
- CentOS FastDFS配置之常见错误
- IOS缓存机制详解
- mvc 数据验证金钱格式decimal格式验证
- Insertion Sort List
- Cocos2dx 3.10音频无法正常播放问题的解决之路
- 控制面板有u盘显示,可是计算机不显示u盘符