Highways
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 27912   Accepted: 12734

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

题意:Flatopia岛要修路,这个岛上有n个城市,要求修完路后,各城市之间可以相互到达,且修的总
路程最短.
求所修路中的最长的路段

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define N 510
struct node{
int x,y,v;
}e[N*N];
int t,fa[N];
bool cmp(const node &a,const node &b){
return a.v<b.v;
}
int find(int x){
return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(){
scanf("%d",&t);
while(t--){
int n,cnt=;
scanf("%d",&n);
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
int x;
scanf("%d",&x);
if(x){
e[++cnt].x=i;e[cnt].y=j;e[cnt].v=x;
}
}
}
int k=,res=;
sort(e+,e+cnt+,cmp);
for(int i=;i<=cnt;i++){
int fx=find(e[i].x),fy=find(e[i].y);
if(fx!=fy){
fa[fy]=fx;
k++;
}
if(k==n-){
res=e[i].v;//因为排完序了,所以最后一个就是最大的
break;
}
}
printf("%d\n",res);
for(int i=;i<=n;i++) fa[i]=;//养成清零好习惯
for(int i=;i<=n;i++) e[i]=e[];
}
return ;
}

poj2485的更多相关文章

  1. poj2485&&poj2395 kruskal

    题意:最小生成树的最大边最小,sort从小到大即可 poj2485 #include<stdio.h> #include<string.h> #include<algor ...

  2. POJ2485 最小生成树

    问题:POJ2485 本题求解生成树最大边的最小值 分析: 首先证明生成树最大边的最小值即最小生成树的最大边. 假设:生成树最大边的最小值比最小生成树的最大边更小. 不妨设C为G的一个最小生成树,e是 ...

  3. POJ-2485 Highways---最小生成树中最大边

    题目链接: https://vjudge.net/problem/POJ-2485 题目大意: 求最小生成树中的最大边 思路: 是稠密图,用prim更好,但是规模不大,kruskal也可以过 #inc ...

  4. 最小生成树Prim poj1258 poj2485 poj1789

    poj:1258 Agri-Net Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u ...

  5. poj2485 kruskal与prim

    Kruskal: #include<iostream> #include<cstdio> #include<algorithm> using namespace s ...

  6. poj2485 Highways

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

  7. POJ2485 Highways(最小生成树)

    题目链接. 分析: 比POJ2253要简单些. AC代码: #include <iostream> #include <cstdio> #include <cstring ...

  8. POJ2485——Highways

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

  9. poj2485 highwaysC语言编写

    /*HighwaysTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 33595Accepted: 15194DescriptionTh ...

  10. POJ2485:Highways(模板题)

    http://poj.org/problem?id=2485 Description The island nation of Flatopia is perfectly flat. Unfortun ...

随机推荐

  1. BAT文件使程序具有以系统权限运行的效果

    @echo off if "%1" == "h" goto begin mshta vbscript:createobject("wscript.sh ...

  2. Javascript中的高阶函数介绍

    高阶函数:高阶看上去就像是一种先进的编程技术的一个深奥术语,一开始我看到的时候我也这样认为的. Javascript的高阶函数 然而,高阶函数只是将函数作为参数或返回值的函数.以下面的Hello,Wo ...

  3. iOS 执行时

    一.什么是执行时(Runtime)? 执行时是苹果提供的纯C语言的开发库(执行时是开发中经经常使用到的底层技术) 二.执行时的作用? 能获得某个类的全部成员变量 能获得某个类的全部属性 能获得某个类的 ...

  4. 如果你还有以下这些现象,那你仍是PHP菜鸟:

    最近看了个文章,写的很精辟,跟大家分享一下,这也是我的目标: 如果你还有以下这些现象,那你仍是PHP菜鸟:1. 不会利用如phpDoc这样的工具来恰当地注释你的代码:2. 对优秀的集成开发环境如Zen ...

  5. 懒人学习automake, Makefile.am,configure.ac(转)

    已经存在Makefile.am,如何生成Makefile? 步骤: [root@localhost hello]# autoscan .///在当前文件夹中搜索 [root@localhost hel ...

  6. EFCore & Mysql migration on Production

    最好的办法是通过脚本进行生产环境数据库更新. 如: dotnet ef migration script -i -o "script.sql". 这样将会产生一个你不用在意线上版本 ...

  7. C#IAsyncResult异步回调函数的解释

    问题:IAsyncResult ar 是如何通过ar.AsyncState强制转换成TCPClientState类型 答:实例中使用的方法如下 我给IAsyncResult ar传入了TCPClien ...

  8. jQuery 基础学习笔记总结(一)

    Jquery 学习笔记 总结 感想: 此前在做站点时用到过jquery相关,特别是Ajax相关技术.但是并没有系统的进行学习和了解Jquery的强大的功能,趁这几天跟着资料基本的了解下Jquery的特 ...

  9. BMFont中文字体图集制作的方法~(for unity ngui)

    BMFont中文字体图集制作的方法~(for unity ngui) 好吧~似乎这个问题困扰了很多人,游戏开始中文化是个不错的事儿啊,这里我就做下说明,如何制作中文字体图集~ 这里的字库图集的制作更多 ...

  10. nodejs 学习资料大全

    1.blog学习篇 http://blog.fens.me/series-nodejs/ 从零开始nodejs系列文章