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
 /*题目大意:描述 :有个城市叫做H市。其中有很多个村庄,村庄之间通信基本靠吼,
交通基本靠走,很不方便。这个市长知道了这个情况,为了替市民着想,决定修建高铁。
每修建一米花费1美元。现在市长请了最著名的工程师来修建高铁,自然这个工程师会让修建高铁的费用最少。
不幸的是,在修建了高铁之后就病逝了。现在市长希望知道在修建完成的这些高铁路中最小生成树中最大的边的值。
他请你来帮助他,如果你计算正确,市长将会送你一辆兰博基尼。
输入:
第一行一个数T,表示接下来有多少组数据。
接下来每组测试数据的第一行有一个数N(3<=N<=500),表示村庄数目。然后是一个二维数组,
第i行第j列表示第i个村庄到第j个村庄的距离。 输出:
只有一个数,输出市长希望知道的已经修成的高铁中最小生成树中最大的边的值。*/
#include<cstdio>
#include<algorithm>
using namespace std;
int fa[];
struct stu
{
int from,to,al;
}st[];
bool cmp(stu a,stu b)
{
return a.al<b.al;
}
int find(int a)
{
int r=a;
while(r != fa[r])
{
r=fa[r];
}
return r;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i,j,a,k,n,min=;
int num=-;
scanf("%d",&n);
for(i = ; i <= n ; i++)
{
fa[i]=i;
}
for(i = ; i <= n ; i++)
{
for(j = ; j <= n ; j++)
{
scanf("%d",&a);
if(i < j) //i到j的距离和j到i的距离一样,避免重复保存
{
num++;
st[num].from=i;
st[num].to=j;
st[num].al=a;
}
}
}
k=;
sort(st,st+num+,cmp); //按两地间的距离从小到大排序
for(i = ; i <= num ; i++)
{
if(k == n-) //n个节点需要n-1个边
{
break;
}
if(find(st[i].from) != find(st[i].to))
{
fa[find(st[i].from)] = find(st[i].to);
k++;
}
}
printf("%d\n",st[i-].al); //因为按两地距离最近的开始找,所以找到n-1个有效边的时,第n-1个边最大
}
}

最新文章

  1. CSharpGL(18)分别处理glDrawArrays()和glDrawElements()两种方式下的拾取(ColorCodedPicking)
  2. 最近Google经常打不开?
  3. HTML标签----图文详解
  4. 在Windows下快速搭建SVN服务器 VisualSVN
  5. 微信开发之——Php批量生成带参数的二维码
  6. USB开发——内核USB驱动+libusb开发方法
  7. 括号配对问题--nyoj-2(栈)
  8. eclipse the user operation is waiting for building workspace&quot; to complete
  9. 怎么样putty打开图形化管理工具,在终端上
  10. Glue4Net简单部署基于win服务的Socket程序
  11. KeepAlive随笔
  12. 漫话JavaScript与异步&#183;第三话——Generator:化异步为同步
  13. tensorflow import 没找到cudnn库问题解决
  14. KafkaManager编译安装使用(支持kerberos认证)
  15. View的getMeasuredWidth和getWidth有什么区别?
  16. 用xcode9编译出ios越狱机程序使用的dylib
  17. linux下内核的配置和编译(2017-1-17)
  18. 我有特殊的Windows激活姿势
  19. SQL Server 数据库中的几个常见的临界值
  20. 文件和打印机共享 win7 and xp

热门文章

  1. 我人生中的第一场Java面试
  2. 使用Spring MVC的@RequestBody注解接收Json对象字符串
  3. document.body 与 document.documentElement区别介绍
  4. Dima and Magic Guitar CodeForces - 366E
  5. 1536 不一样的猜数游戏 dp思维 + 找规律
  6. scau 1144 数星星 bit + 扫描线的思想
  7. C#基础学习4
  8. P1615 西游记公司
  9. window服务 调试步骤
  10. BottomNavigationBar底部导航条用法