Highways
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 22842   Accepted: 10525

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.

Source

POJ Contest,Author:Mathematica@ZSU

求MST中的最大边

#include <stdio.h>
#include <string.h> #define maxn 505
#define inf 0x3f3f3f3f int G[maxn][maxn], n;
int dis[maxn];
bool vis[maxn]; void getMap() {
scanf("%d", &n);
int i, j;
for(i = 0; i < n; ++i)
for(j = 0; j < n; ++j)
scanf("%d", &G[i][j]);
} int getNext() {
int i, pos = -1, val = inf;
for(i = 0; i < n; ++i)
if(!vis[i] && dis[i] < val) {
val = dis[i]; pos = i;
}
return pos;
} void solve() {
int i, u, ans = 0;
for(i = 0; i < n; ++i) {
vis[i] = 0; dis[i] = inf;
}
dis[u=0] = 0;
while(u != -1) {
vis[u] = 1;
if(ans < dis[u]) ans = dis[u];
for(i = 0; i < n; ++i)
if(!vis[i] && dis[i] > G[u][i])
dis[i] = G[u][i];
u = getNext();
}
printf("%d\n", ans);
} int main() {
int t;
scanf("%d", &t);
while(t--) {
getMap();
solve();
}
return 0;
}

POJ2485 Highways 【MST】的更多相关文章

  1. 【MST】P2323 [HNOI2006]公路修建问题

    Description 给定 \(n\) 个点 \(m - 1\) 条无向边,每条边有两种边权,贵一点的和便宜一点的.要求至少选择 \(k\) 条贵边使得图联通且花费最大的边权值最小. Input 第 ...

  2. Bzoj1083 1083: [SCOI2005]繁忙的都市【MST】

    大水题,真不知道出题者是怎么把这么水的题出的这么长的TAT 其实这题在于考语文水平,一共三个要求,前两个要求意思就是要选出的道路是树形的,最后一个要求就是要权值最小,于是整个题意说白了就是求一棵MST ...

  3. Codeforces 1095F Make It Connected 【MST】

    <题目链接> 题目大意: 给定一张n个顶点(每个顶点有点权)的无向图,并且给出边权为wi的m条边,顶点u和顶点v直接如果建边,边权为a_u + a_v,求图连通的最小边权和. 解题分析: ...

  4. POJ1751 Highways【最小生成树】

    题意: 给你N个城市的坐标,城市之间存在公路,但是由于其中一些道路损坏了,需要维修,维修的费用与公路长成正比(公路是直的). 但现有M条公路是完整的,不需要维修,下面有M行,表示不需要维修的道路两端的 ...

  5. 【转】并查集&MST题集

    转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...

  6. 【AtCoder3611】Tree MST(点分治,最小生成树)

    [AtCoder3611]Tree MST(点分治,最小生成树) 题面 AtCoder 洛谷 给定一棵\(n\)个节点的树,现有有一张完全图,两点\(x,y\)之间的边长为\(w[x]+w[y]+di ...

  7. 【AtCoder2134】ZigZag MST(最小生成树)

    [AtCoder2134]ZigZag MST(最小生成树) 题面 洛谷 AtCoder 题解 这题就很鬼畜.. 既然每次连边,连出来的边的权值是递增的,所以拿个线段树xjb维护一下就可以做了.那么意 ...

  8. 【LCA+MST】BZOJ3732-Network

    [题目大意] 给你N个点的无向图 (1 <= N <= 15,000),记为:1…N.图中有M条边 (1<=M<=30,000) ,第j条边的长度:d_j (1<=d_j ...

  9. 【CF125E】MST Company(凸优化,最小生成树)

    [CF125E]MST Company(凸优化,最小生成树) 题面 洛谷 CF 题解 第一眼看见就给人丽洁姐那道\(tree\)一样的感觉. 那么二分一个权值,加给所有有一个端点是\(1\)的边, 然 ...

随机推荐

  1. 路飞学城Python-Day12

    7月10日安排  完成所有函数作业和思维导图整理   [45.函数-生成器] 如果数据是有规律的,就可以先生成一个数据,等数据执行的时候再执行,也就是在真正调用数据之前,拿到数据的生成规律,而是拿到生 ...

  2. js 将数组中的每一项安装奇偶重新组合成一个数组对象

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. 服务器搭建域控与SQL Server的AlwaysOn环境过程(四)配置AlwaysOn

    0 引言 这一篇才真正开始搭建AlwaysOn,前三篇是为搭建AlwaysOn 做准备的. 步骤 1.3 配置AlwaysOn 请先使用本地用户Administrator登录这两个集群节点并执行下面的 ...

  4. 字符串的格式化(转自武sir)

    百分号s方式: (name)      可选,用于选择指定的key flags          可选,可供选择的值有: +       右对齐:正数前加正好,负数前加负号: -        左对齐 ...

  5. mven系列问题

    1.前言 Maven,发音是[`meivin],"专家"的意思.它是一个很好的项目管理工具,很早就进入了我的必备工具行列,但是这次为了把 project1项目完全迁移并应用mave ...

  6. CSS 清除浮动 伪类

    参考链接:https://www.cnblogs.com/yingsu/p/7261904.html 不清楚浮动的结果和影响不再描述,清除浮动的代码别处也有很多,每种方法都有十分简洁的代码,我今天学到 ...

  7. 紫书 例题8-8 UVa 1471 (用set实现动态二分)

    设切割的区间为(j, i), 注意两边都是开区间. 然后可以预处理出以i为起点的最长连续递增的长度和以j为终点的最长连续递增的长度. 大致思路就是枚举i,右边这一侧的最优值就知道了, 然后这道题的关键 ...

  8. SSH的理解

    SSH的利用,通俗的讲就是一个网络传输数据的加密协议,目前有一些基于SSH的构建了服务器-客户端的软件工具,在Windows上装一个客户端,Linux上则为服务端,这样就可以把Windows上写的内容 ...

  9. Jquery控件jrumble

    <!DOCTYPE HTML> <html>  <head>   <title>demo.html</title>   <meta h ...

  10. 大浪淘沙,JSP终将死去

    首先讲明,我不是标题党. 这纯属我个人的意见.勿喷. 先来讲讲JSP是怎么出现的吧. 在早期的WEB中,JS.CSS远未成熟,技术慷慨向并不明白!因为前端语言的匮乏.各家大公司都推出基于后端的模板语言 ...