poj 2485 Highways
来源:互联网 发布:mysql 新增数据库 编辑:程序博客网 时间:2024/06/16 12:52
Description
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 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
Sample Input
130 990 692990 0 179692 179 0
Sample Output
692
Hint
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int set1[501];
int p[501][501];
struct Node
{
int a,b;
int len;
}s[1000000];
bool cmp(Node a,Node b)
{
return a.len<b.len;
}
int set_find(int x)
{
if(x==set1[x])
return x;
return set1[x]=set_find(set1[x]);
}
int main()
{
int T;
cin>>T;
while(T--)
{
int N,i,j,k=0;
cin>>N;
for(i=1;i<=N;i++)
set1[i]=i;
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
scanf("%d",&p[i][j]);
k=0;
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
if(i!=j&&p[i][j]!=0&&p[j][i]!=0)
{
s[k].a=i; s[k].b=j;s[k].len=p[i][j];
p[i][j]=p[j][i]=0;
k++;
}
sort(s,s+k,cmp);
int mark;
for(i=0;i<k;i++)
{
int fa=set_find(s[i].a);
int fb=set_find(s[i].b);
if(fa!=fb)
{set1[fb]=fa;mark=i;}
}
cout<<s[mark].len<<endl;
}
return 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
- MQTT学习笔记——树莓派MQTT客户端 使用Mosquitto和paho-python
- Http请求过程中,get和post请求方式的区别
- HDU 5000 Clone(瞎搞)
- 类似于falsh图片切换效果
- mysql密码修改
- poj 2485 Highways
- Search Insert Position
- 图片放大镜效果
- JDK8新特性(部分)
- Android文件存储详细完整示例
- bitset类
- C++ string类的隐式共享写时拷贝的实现及设计要点
- HDU 4998 Rotate
- ext消息框