Highways
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 28440 |
|
Accepted: 12962 |
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.
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.
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
1
3
0 990 692
990 0 179
692 179 0
Sample Output
692
Hint
Huge input,scanf is recommended.
Source
POJ Contest,Author:Mathematica@ZSU
题意:
什么也不多说,题意对于英语不好的同学是障碍,我也是看了翻译才懂!
求的是 MST 的最大权值边。
键入数据:
村庄的数目 n
村庄 1 1的距离 ,村庄1 2 的距离 村庄 1 3的距离 ,......村庄 1 n 的距离
村庄 2 1的距离 ,村庄2 2 的距离 村庄 2 3的距离 ,......村庄 2 n 的距离
.................................
村庄 n 1的距离 ,村庄n 2 的距离 村庄 n 3的距离 ,......村庄 n n 的距离
题目没懂,测试数据看了很久,最后运行错误!数组开小了!挂了很多次。。。。。
代码:
#include
#include
#include
using namespace std;
const int MYDD=110300;
int set[MYDD];
void init(int x) {//还是有参数好一点
for(int j=1; j<=x; j++)
set[j]=j;
}
int find(int x) {
int t,child=x;
while(x!=set[x])
x=set[x];
while(child!=x) {
t=set[child];// t 记录当前父节点
set[child]=x;
child=t;
}
return x;
}
bool combine(int x,int y) {//判断是否有同一个根节点
int fx=find(x);
int fy=find(y);
if(fx!=fy) {
set[fx]=fy;
return true;//不成环
}
return false;
}
struct EDGE {
int u,v,w;
} edge[MYDD*8];
bool cmp(EDGE x,EDGE y) {
return x.wmax)
max=edge[j].w;
}
}
// printf("%d\n",ans);
printf("%d\n",max);
}
return 0;
}
后:GF来了。
**********************************