poj 2485 最小生成树中的最大边 prim
来源:互联网 发布:Windows切换目录 编辑:程序博客网 时间:2024/05/16 03:02
Highways
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 25224 Accepted: 11654
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<cstring>#define INF 0x3f3f3f3fusing namespace std;int n;int Map[1000][1000];int edge[1000][1000];int low[1000],next[1000];int Prim(){int MM=-1;for(int i=0;i<n;i++){next[i]=0;low[i]=edge[0][i];}next[0]=-1;for(int i=0;i<n-1;i++){int Min=INF;int v=-1;for(int j=0;j<n;j++){if(next[j]!=-1&&low[j]<Min){Min=low[j];v=j;}}if(v!=-1){//Map[next[v]][v]=low[v];if(MM<low[v])MM=low[v];next[v]=-1;for(int j=0;j<n;j++){if(next[j]!=-1&&low[j]>edge[v][j]) //大小比较别写倒了{low[j]=edge[v][j];next[j]=v;}}}}printf("%d\n",MM);}int main(){int T,i,j;scanf("%d",&T);while(T--){scanf("%d",&n);for(i=0;i<n;i++){for(int j=0;j<n;j++)scanf("%d",&edge[i][j]);}Prim();}}
0 0
- poj 2485 最小生成树中的最大边 prim
- poj 2485 Highways prim最小生成树 基础 球最小生成树中得最大边
- poj2253 最小生成树中的最大边 prim
- poj 2485(最小生成树 Prim)
- poj 2485 Highways prim最小生成树
- poj 2485(prim最小生成树)
- POJ 2485 Highways (prim最小生成树)
- POJ 2485 Highways 【最小生成树Prim】
- poj 2485 prim算法最小生成树
- poj 2377-prim(最小生成树的最大边权的和)
- POJ 2395 Out of Hay(最小生成树—prim算法记录最大边)
- prim算法求最小生成树的最大边--poj2253
- POJ 2485-Highways 最小生成树Prim算法
- POJ 2485 Highways(prim 最小生成树)
- POJ 2485 Highways 图论 prim算法 最小生成树
- POJ 2485 Highways(最小生成树 Prim)
- poj 2485 Highways(kruscal or prim最小生成树)
- POJ 2485:Highways:典型prim最小生成树(2)
- C++类的使用
- 在eclipse中JAVA从打包成jar程序到双击运行的整个过程(没有主清单属性问题的解决)
- Eclipse搭建Android开发环境-Android SDK和ADT离线安装
- 九度oj 1129
- 解析json数据
- poj 2485 最小生成树中的最大边 prim
- Python爬虫学习记录(1)——百度贴吧图片下载
- BC-52-1001
- android-使用webview来开发混合应用
- UILabel
- poj 1258 最小生成树 prim
- Socket编程步骤
- hdu1014 Uniform Generator
- 我们被叫做90后 | 致青春(催泪好文,自备纸巾)