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 ...
随机推荐
- CSF 中的应用程序请求路由
编辑人员注释:本文章由 AzureCAT 团队的 Christain Maritnez 撰写. 应用程序请求路由(简称为 ARR)可能是 Microsoft 使用的技术中讨论得最少但极为重要的技术之一 ...
- HDU1181【有向图的传递闭包】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1181 题意很简单. 有用并查集做的.我这里用传递闭包做. 有向图的传递闭包采用Floyd思想,可以判断 ...
- GTW likes math(简单数学)
GTW likes math Accepts: 472 Submissions: 2140 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- BI系统的应用组织思路与数据分析模式
BI商业智能软件一般都会提供若干数据整合.数据查询.分析与评价.数据可视化及数据分享的手段,但是在BI项目的构建与实施过程中,如果不按照一定的应用组织思路.数据分析模式及分析流程使用这些工具或手段,呈 ...
- WLAN和WIFI的区别
在刚刚为大家介绍的wifi上网是什么意思?文章中为大家介绍了什么wifi无线上网,但大家可能会有这样的疑问,听说最多的应该是WLAN无线上网,很多笔记本电脑使用的都是WLAN无线上网,那么wlan和w ...
- HDU 1465 不容易系列之排错
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 大家常常感 ...
- win7如何快速设置开机启动项?
添加开机启动项方法: 找到windows开始菜单->所有程序->启动,右键打开, 进入C:\Users\Ocean\AppData\Roaming\Microsoft\Windows\St ...
- s3c2440栈分配情况(fl2440裸机 stack)
//2440INIT.S ;The location of stacks UserStack EQU (_STACK_BASEADDRESS-0x3800) ;0x33ff4800 ~ SVCStac ...
- BZOJ 2100: [Usaco2010 Dec]Apple Delivery( 最短路 )
跑两遍最短路就好了.. 话说这翻译2333 ---------------------------------------------------------------------- #includ ...
- js的初始化
在项目中遇到了类似于这样的js, myinit.js文件: var wyl_01 = { tip : function(msg){ alert('i am a tip,msg:'+msg); }, t ...