Highways
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 23426   Accepted: 10829

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 <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#define INF 999999999
#define MIN -1
#define N 500+10 using namespace std; int map[N][N];
bool vis[N];
int dis[N];
int n, ans; void prim()
{
ans=MIN; //最小生成树的权值和初始化0
int mm;
int i, j;
memset(vis, false, sizeof(vis));
for(i=0; i<n; i++)
{
dis[i]=map[0][i];
}
vis[0]=true;
int pos;
for(i=0; i<n-1; i++)
{
mm=INF;
for(j=0; j<n; j++)
{
if(vis[j]==false && dis[j]<mm)
{
mm=dis[j];
pos=j;
}
}
if(mm>ans) ans=mm;
vis[pos]=true;
for(j=0; j<n; j++)
{
if(vis[j]==false && dis[j]>map[j][pos] )
{
dis[j]=map[j][pos];
}
}
}
printf("%d\n", ans );
} int main()
{
int i, j;
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
scanf("%d", &map[i][j] );
}
}
prim();
}
return 0;
}

POJ 2485 Highways(最小生成树+ 输出该最小生成树里的最长的边权)的更多相关文章

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

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

  2. poj 2485 Highways

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

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

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

  4. POJ 2485 Highways (求最小生成树中最大的边)

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

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

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

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

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

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

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

  8. poj 2485 Highways 最小生成树

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

  9. poj 2485 Highways(最小生成树,基础,最大边权)

    题目 //听说听木看懂之后,数据很水,我看看能不能水过 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stri ...

随机推荐

  1. HDU 2586 How far away ? 离线lca模板题

    How far away ? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. [Bzoj4942][Noi2017]整数(线段树)

    4942: [Noi2017]整数 Time Limit: 50 Sec  Memory Limit: 512 MBSubmit: 363  Solved: 237[Submit][Status][D ...

  3. HDU - 3664 Permutation Counting

    Discription Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the amount of ...

  4. ApplicationContext介绍

    如果说BeanFactory是Spring的心脏,那么ApplicationContext就是完整的身躯了.ApplicationContext由BeanFactory派生而来,提供了更多面向实际应用 ...

  5. Generate C and C++ Header File

    1. 2. 其中bootclasspath 后面的参数就是自己android.jar具体位置 location: ${system_path:javah} working Directoy: ${pr ...

  6. 【sublime text 3】sublime text 3 汉化

    快捷键:Ctrl+Alt+P 输入快捷键Ctrl+Shift+P 在出现的文本框中输入Install Package(或直接输入“ip”)选中packageControl:Install Packag ...

  7. 【IntelliJ IDEA】idea导入项目只显示项目中的文件,不显示项目结构

    导入项目之后,只显示项目文件,不显示项目结构 解决方法 1.点击file->project structure..->Modules 点击右上角+加号 ->import Module ...

  8. 如何模拟alert/confirm/prompt实现阻断程序运行

    场景:在执行js的时候,我们希望运行到某处,进行用户交互,根据交互的内容,运行下面的程序:下面的js程序需要用的和用户交互的内容,所以,和用户交互时,后面的程序必须停止运行 方案: 1. 原生的ale ...

  9. DELPHI的BPL使用

    了解BPL和DLL的关系将有助于我们更好地理解DELPHI在构件制作.运用和动态.静态编译的工作方式.对初学DELPHI但仍对DELPHI开发不甚清晰的朋友有一定帮助.第一部分:有关包的介绍 一般我们 ...

  10. 【Todo】Java学习路线(方向指导)

    在网上搜了下Java学习路线(关键词:学习,因为众所周知,实践出牛人,在平时工作不怎么深入的情况下,才强调学习的方向的重要性 ^_^) 发现下面知乎这个回答写的真好.mark如下: https://w ...