poj 2485 Highways
来源:互联网 发布:时时彩平台源码下载 编辑:程序博客网 时间:2024/06/06 07:14
Highways
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 24142 Accepted: 11138
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
求mst的最大边。。
#include <iostream>#include <string.h>#define Max 2333#define INF 1000000using namespace std;int n,m;char t[Max][10];int edge[Max][Max];int lowcost[Max];int nearvex[Max];void prim(int u0){int sumweight = 0;for(int i=1;i<=n;i++){lowcost[i]=edge[u0][i];nearvex[i]=u0;}nearvex[u0]=-1;for(int i=1;i<n;i++){int min=INF;int v=-1;for(int j=1;j<=n;j++){if(nearvex[j]!=-1&&lowcost[j]<min){v=j;min=lowcost[j];}}if(v!=-1){nearvex[v]=-1;//²åÈëÒ»Ìõ±ßif(sumweight<lowcost[v])sumweight=lowcost[v];for(int j=1;j<=n;j++){if(nearvex[j]!=-1&&edge[v][j]<lowcost[j]){lowcost[j]=edge[v][j];nearvex[j]=v;}}}}cout<<sumweight<<endl;}int main(){int T;cin>>T;while(T--){cin>>n;memset(edge,0,sizeof(edge));for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>edge[i][j];prim(1);}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基础——网络编程
- Validate Binary Search Tree
- light oj 1422 Halloween Costumes(区间dp)
- POJ - 2446 Chessboard 二分图 最大匹配(输入坑)
- C/C++文件之eof()
- poj 2485 Highways
- 字符串拷贝函数的安全用法模板
- 二叉树结点
- 汉诺塔分治演示备忘
- 二叉树
- Java中==和equals()方法的区别
- 浅谈C语言中的联合体
- python数据挖掘领域工具包
- php正则表达式—基本语法