poj 2485
来源:互联网 发布:淘宝店铺商品怎么分类 编辑:程序博客网 时间:2024/05/21 12:44
Highways
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 22691 Accepted: 10459
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 <cstdio>#include <cstring>#include <algorithm>using namespace std;#define maxn 510int r[maxn*maxn],u[maxn*maxn],v[maxn*maxn],w[maxn*maxn];int fa[maxn*maxn];int find(int x){if(fa[x]!=x){fa[x]=find(fa[x]);}return fa[x];}bool cmp(const int i,const int j){return w[i]<w[j];}int main(){int t,n,i,j,k;scanf("%d",&t);while(t--){scanf("%d",&n);k=0;for(i=1;i<=n;i++){ for(j=1;j<=n;j++) { u[k]=i; v[k]=j; scanf("%d",&w[k]); k++; }}for(i=1;i<=n*n;i++){r[i]=i;fa[i]=i;}sort(r,r+k,cmp);int sum=-1,cnt=0;;for(i=0;i<k;i++){int e=r[i];int x=find(u[e]);int y=find(v[e]);if(cnt==n-1)break;if(x!=y){if(sum<w[e])sum=w[e];fa[y]=x;cnt++;}}printf("%d\n",sum);}return 0; }
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
- The type javax.http.HttpServletRequest cannot be resolved.It is indirectly……问题之解决
- android列表分组及字母导航-重构(2)-注解
- iPhone Instruments工具使用_检测内存泄露(转)
- 好多东西都没记录,罪过啊~
- 使用Xcode和Instruments调试解决iOS内存泄露(转)
- poj 2485
- 【Maven】Apache Maven 安装介绍
- Android 自定义view实例:跟踪手指小球
- 银行软件测试工作量分析和评估方法(转)
- windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTim
- android网络编程 -- HTTP通信(01)TOMCAT HTTP服务器搭建
- android布局技巧:创建高效布局
- js动态删除表格中的行和列
- CCString的简单使用