Highways
来源:互联网 发布:sql删除表中全部数据 编辑:程序博客网 时间:2024/05/22 06:44
Highways
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 29345 Accepted: 13366
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
这道题就是最小生成树,取树中权值最大的输出
注意要用scanf输入
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int main(){int mp[510][510],dis[510]; int t,n,i,j; scanf("%d",&t); while(t--) { cin>>n; for(i=1;i<=n;i++) for(j=1;j<=n;j++)scanf("%d",&mp[i][j]);int max=0;for(j=1;j<=n;j++)dis[j]=mp[1][j];for(i=1;i<n;i++){int min=65536,p;for(j=1;j<=n;j++){if(dis[j]&&dis[j]<min){min=dis[j];p=j;}}if(min>max)max=min;dis[p]=0;for(j=1;j<=n;j++)if(dis[j]>mp[p][j])dis[j]=mp[p][j];}cout<<max<<endl; } return 0;}
0 0
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- highways
- lua的Table.getn在MAC上使用问题
- <1>CComboBoxEx添加图像CImageList无法正常显示
- LayoutInflater是如何“移花接木”-上篇
- c++中必须在类初始化列表中初始化的几种情况摘要
- 为啥继承时基类的析构一般声明为虚函数
- Highways
- 深度探索c++对象模型之带有constructor类数组的new语义学
- 数据通信与计算机网络
- OpenGL如何显示透明PNG
- 数据结构实验之查找一:二叉排序树
- Tyvj 1363 火车进出栈问题 (高精度+卡特兰数+组合数学)
- Unity使用VS开发编码格式的问题
- mini2440 系统安装
- ionic解决gulp.task中sass不正常工作[已解决]