POJ2485——Highways
Description
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 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
Sample Input
1 3
0 990 692
990 0 179
692 179 0
Sample Output
692
Hint
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include<vector>
#include<deque>
#include<list>
using namespace std;
int n;
int i,j;
int map[550][550];
bool mark[550];
int prim()
{
int w=n;
int k;
int len;
int max=-1;
while(--w)
{
int min=999999;
int y=0;
for(i=2;i<=n;i++)
{
if(!mark[i]&&map[1][i]<min)
{
min=map[1][i];
k=i;
}
}
mark[k]=1;
if(max<min)
max=min;
for(i=2;i<=n;i++)
{
if(!mark[i]&&map[k][i]<map[1][i])
map[1][i]=map[k][i];
}
}
return max;
}
int main()
{
int test;
scanf("%d",&test);
while(test--)
{
memset(map,0,sizeof(map));
memset(mark,0,sizeof(mark));
scanf("%d",&n);
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
scanf("%d",&map[i][j]);
printf("%d\n",prim());
}
return 0;
}
POJ2485——Highways的更多相关文章
- poj2485 Highways
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- POJ2485:Highways(模板题)
http://poj.org/problem?id=2485 Description The island nation of Flatopia is perfectly flat. Unfortun ...
- POJ2485 Highways 【MST】
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22842 Accepted: 10525 Descri ...
- POJ2485 Highways(最小生成树)
题目链接. 分析: 比POJ2253要简单些. AC代码: #include <iostream> #include <cstdio> #include <cstring ...
- 最小生成树Prim poj1258 poj2485 poj1789
poj:1258 Agri-Net Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u ...
- POJ 1258 Agri-Net|| POJ 2485 Highways MST
POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> ...
- MST系列
1.POJ2485 Highways 蛮水的 数组一开始开小了卡了一会儿 我可能是个傻逼 #include<iostream> #include<cstdio> #includ ...
- poj图论解题报告索引
最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman- ...
- H:Highways
总时间限制: 1000ms 内存限制: 65536kB描述The island nation of Flatopia is perfectly flat. Unfortunately, Flatopi ...
随机推荐
- HDU 2178 猜数字
题解:设猜到的最大的数是h,在1到h间,你最多只要猜log2(h)+1(取整)次,所以易知==>h=2^m-1.即猜m次,能猜到的最大的数为2^m-1. #include <cstdio& ...
- Suricata, to 10Gbps and beyond(X86架构)
Introduction Since the beginning of July 2012, OISF team is able to access to a server where one int ...
- junit学习笔记(二):hamcrest和TestSuit
1. hamcrest hamcrest可以有效增加junit的测试能力,用一些对通俗语言来进行测试. Hamcrest 是一个测试的框架,它提供了一套通用的匹配符 Matcher,灵活使用这些匹配符 ...
- 获得view所在的控制器
- (UIViewController*)getViewController{ for (UIView* next = [self superview]; next; next = next.supe ...
- 自定义cell时,在宽的手机上显示太窄解决办法
1.工程设置要如下:见第二个红框,清除launch screan file 后面的内容 2.自定义的cell要设置auto layout 和size clases
- spring注解开发中常用注解以及简单配置
一.spring注解开发中常用注解以及简单配置 1.为什么要用注解开发:spring的核心是Ioc容器和Aop,对于传统的Ioc编程来说我们需要在spring的配置文件中邪大量的bean来向sprin ...
- _int64、long long 的区别
C++的64位整数[原]by 赤兔 http://baike.baidu.com/view/1235293.htm 在做ACM题时,经常都会遇到一些比较大的整数.而常用的内置整数类型常常显得太小了:其 ...
- Nginx阅读笔记(四)之root和alias
nginx指定文件路径有两种方式root和alias,这两者的用法区别,使用方法总结了下,方便大家在应用过程中,快速响应.root与alias主要区别在于nginx如何解释location后面的uri ...
- Python IDLE快捷键
编辑状态时:Ctrl + [ .Ctrl + ] 缩进代码Alt+3 Alt+4 注释.取消注释代码行Alt+5 Alt+6 切换缩进方式 空格<=>TabAlt+/ 单词完成,只要文中出 ...
- window下nodejs安装指南
相信对于很多关注javascript发展的同学来说,nodejs已经不是一个陌生的词眼.有关nodejs的相关资料网上已经铺天盖地.由于它的高并发特性,造就了其特殊的应用地位. 国内目前关注最高,维护 ...