Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21628   Accepted: 9970

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

这题写的真烦。

各种不知道的莫名其妙的


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath> using namespace std; const int INF=1000000000;
const int N=510;
int map[N][N];
int vis[N];
int ans;
int dis[N]; void prim(int n)//prim求最小生成树
{
memset(vis, 0, sizeof(vis));
for(int i=1; i<=n; i++)
{
dis[i] = INF;
}
dis[1] = 0;
ans = 0;
for(int i=1; i<=n; i++)
{
int temp = INF, k = 0;
for(int j=1; j<=n; j++)
{
if(!vis[j] && dis[j]<temp)
{
temp = dis[j];
k = j;
}
}
vis[k] = true;
if(ans<temp) ans = temp;
for(int j=1; j<=n; j++)
{
if(!vis[j] && dis[j]>map[k][j])
{
dis[j] = map[k][j];
}
}
}
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n;
scanf("%d", &n);
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
scanf("%d", &map[i][j]);
}
}
prim(n);
printf("%d\n", ans);
}
return 0;
}

错误。。

版权声明:本文博客原创文章,博客,未经同意,不得转载。

POJ 2485:Highways(最小生成树&amp;&amp;prim)的更多相关文章

  1. POJ 2485 Highways(最小生成树+ 输出该最小生成树里的最长的边权)

                                                                                                         ...

  2. poj 2485 Highways 最小生成树

    点击打开链接 Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19004   Accepted: 8815 ...

  3. POJ 2485 Highways 最小生成树 (Kruskal)

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

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

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

  5. poj 2485 Highways

    题目连接 http://poj.org/problem?id=2485 Highways Description The island nation of Flatopia is perfectly ...

  6. POJ 2485 Highways (prim最小生成树)

    对于终于生成的最小生成树中最长边所连接的两点来说 不存在更短的边使得该两点以不论什么方式联通 对于本题来说 最小生成树中的最长边的边长就是使整个图联通的最长边的边长 由此可知仅仅要对给出城市所抽象出的 ...

  7. POJ 2485 Highways【最小生成树最大权——简单模板】

    链接: http://poj.org/problem?id=2485 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

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

    题目链接 Description The islandnation of Flatopia is perfectly flat. Unfortunately, Flatopia has no publ ...

  9. POJ 1751 Highways(最小生成树Prim普里姆,输出边)

    题目链接:点击打开链接 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has ...

  10. 快速切题 poj 2485 Highways prim算法+堆 不完全优化 难度:0

    Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23033   Accepted: 10612 Descri ...

随机推荐

  1. Libev学习笔记2

    这一节根据官方文档给出的简单示例,深入代码内部,了解其实现机制.示例代码如下: int main (void) { struct ev_loop *loop = EV_DEFAULT; ev_io_i ...

  2. HashMap和HashTable 学习

    1. HashMap 1)  hashmap的数据结构 Hashmap是一个数组和链表的结合体(在数据结构称“链表散列“),如下图示: 当我们往hashmap中put元素的时候,先根据key的hash ...

  3. GDAL1.9.1 IN VS2008 C#中的编译及使用

    下载gdal1.9.1到官网:http://www.gdal.org/ GDAL库的简洁.高效深受开发人员的喜爱,很多开源的GIS软件甚至是商业GIS软件都使用了这个库.GDAL使用C++,在Visu ...

  4. Thrift对多接口服务的支持

    Thrift对多接口服务的支持 Thrift在0.9.1版本之前,一直只提交了对单一接口服务的支持,即一个RPC服务器(对应一个端口)支持一个服务接口的实现. 但是很多时候,我们的服务不能实现在一个接 ...

  5. android 中文 api (71) —— BluetoothServerSocket[蓝牙]

    前言 本章内容是  android.bluetooth.BluetoothServerSocket,为Android蓝牙部分的章节翻译.服务器通讯套接字,与TCP ServerSocket类似.版本为 ...

  6. Duplicate entry &#39;97112&#39; for key 1

    1.错误描写叙述 2014-07-08 10:27:13,939 ERROR(com.you.conn.JDBCConnection:104) -com.mysql.jdbc.exceptions.j ...

  7. 积跬步,聚小流------关于UML类图

    UML的存在 类图是使用频率比較高的UML图,它用于描写叙述系统中所含的类以及它们之间的相互关系,帮助人们简化对系统的理解,也是系统分析和设计阶段的重要产物,也是系统编码和測试的重要类型根据. UML ...

  8. probing元素

    https://msdn.microsoft.com/zh-cn/library/823z9h8w(v=vs.85).aspx 指定加载程序集时公共语言运行库要搜索的应用程序基子目录. <con ...

  9. 用户 'IIS APPPOOL\DefaultAppPool' 登录失败解决办法

    法一:将iis站点的应用程序池的用户改为本地用户,如果所示: 方法二: 1.打开sql server  management studio安全性->登录名->右击新建登录名->常规- ...

  10. BZOJ 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典

    题目 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 401  Solv ...