Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 24383   Accepted: 11243

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.
注意提示,开始我用的cin,cout输入输出,结果超时,看到提示用的scanf就AC了
 #include <stdio.h>
#define INF 65537;
int map[][];
int vis[];
int dis[];
int n;
int Prim(){
for(int i=;i<n;i++){
vis[i]=;
dis[i]=INF;
}
dis[]=;
for(int i=;i<n;i++){
int p;
int mine=INF;
for(int j=;j<n;j++){
if(!vis[j]&&mine>dis[j]){
p=j;
mine=dis[j];
}
}
vis[p]=;
for(int j=;j<n;j++){
if(!vis[j]&&dis[j]>map[p][j])
dis[j]=map[p][j];
}
}
int maxe=;
for(int i=;i<n;i++){
if(maxe<dis[i])
maxe=dis[i];
}
return maxe;
}
int main() { int num;
scanf("%d",&num);
for(int i=;i<num;i++){
scanf("%d",&n);
for(int j=;j<n;j++){
for(int k=;k<n;k++){
scanf("%d",&map[j][k]);
}
}
int maxe=Prim();
printf("%d\n",maxe);
}
return ;
}

Highways - poj 2485 (Prim 算法)的更多相关文章

  1. Highways POJ-1751 最小生成树 Prim算法

    Highways POJ-1751 最小生成树 Prim算法 题意 有一个N个城市M条路的无向图,给你N个城市的坐标,然后现在该无向图已经有M条边了,问你还需要添加总长为多少的边能使得该无向图连通.输 ...

  2. Highways POJ 2485【Prim】

    Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...

  3. Highways poj 2485

    Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...

  4. poj 2485 (kruskal算法)

    /*kruskal算法*/ #include <iostream> //#include <fstream> #include <algorithm> using ...

  5. Agri-Net - poj 1258 (Prim 算法)

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44373   Accepted: 18127 Description F ...

  6. Truck History - poj 1789 (Prim 算法)

      Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20884   Accepted: 8075 Description Ad ...

  7. POJ 2485 Prim 找最长的边

    A国没有高速公路,因此A国的交通很困难.政府意识到了这个问题并且计划建造一些高速公路,以至于可以在不离开高速公路的情况下在任意两座城镇之间行驶. A国的城镇编号为1到N, 每条高速公路连接这两个城镇, ...

  8. 【POJ 2485】Highways(Prim最小生成树)

    题目 Prim算法:任选一个点,加入集合,找出和它最近的点,加入集合,然后用加入集合的点去更新其它点的最近距离......这题求最小生成树最大的边,于是每次更新一下最大边. #include < ...

  9. poj 2485 Highways (最小生成树)

    链接:poj 2485 题意:输入n个城镇相互之间的距离,输出将n个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要 ...

随机推荐

  1. thinkphp3.0增加setInc、setDec方法

    thinkphp3.0增加setInc.setDec方法 thinkphp3.0增加setInc.setDec方法,今天查看thinkphp2.0的方法setInc.setDec时是这样写的: 而对于 ...

  2. 3.非标准的NDEF格式数据解析--IsoDep

    1.使用目的:正常开发是针对NDEF格式数据进行开发,但实际情况并非如此,以厦门公交卡为例,厦门公交卡保存的是非NDEF格式数据.其类型是IsoDep类型. 2.非标准的NDEF格式数据流程:当厦门公 ...

  3. Systemd入门教程:命令篇(转)

    作者: 阮一峰 日期: 2016年3月 7日 Systemd 是 Linux 系统工具,用来启动守护进程,已成为大多数发行版的标准配置. 本文介绍它的基本用法,分为上下两篇.今天介绍它的主要命令,下一 ...

  4. 事件溯源模式(Event Sourcing Pattern)

    此文翻译自msdn,侵删. 原文地址:https://msdn.microsoft.com/en-us/library/dn589792.aspx 本文介绍了一种有利于物化(materialize)领 ...

  5. 监控SQL Server正在执行的SQL语句和死锁情况

    原文:监控SQL Server正在执行的SQL语句和死锁情况 SELECT [Individual Query] = SUBSTRING(qt.TEXT, er.statement_start_off ...

  6. Nand 的几个名词:oob,bbt,ecc

    转:http://blog.csdn.net/lanmanck/article/details/4230904 例如Samsung K9F1208U0B,数据存储容量为64MB,采用块页式存储管理.8 ...

  7. 手动删除SVCH0ST.EXE的方法

        最近几天在办公室的计算机上又发现了一种病毒,在进程管理器中多出了两个进程:SVCH0ST.EXE.IEXPLORE.EXE,经一番查看揭开了它们的真面目,现将清除这种病毒的方法总结如下: 病毒 ...

  8. 为什么代理属性设置成assign为了防止生成保留环来

    循环引用 全部的引用计数系统, 都存在循环应用的问题, 比如以下的引用关系: 1. 对象a创建并引用到了对象b 2. 对象b创建并引用到了对象c 3. 对象c创建并引用到了对象b 这时候b和c的引用计 ...

  9. hibernate.cfg.xml配置文件对关联关系的书写技巧!

    以Department(部门类)和User(用户类)作为例子: 类图如下: 一般hibernate.cfg.xml的配置文件开头都是如下: <?xml version="1.0&quo ...

  10. EL表达式中的empty运算符