POJ 一 2485 Highways(最小生成树)
来源:互联网 发布:按键精灵 链接数据库 编辑:程序博客网 时间:2024/04/30 03:41
Highways
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 19029 Accepted: 8829
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.
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.
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
130 990 692990 0 179692 179 0
Sample Output
692
典型的最小生成树。
在多个村子之间铺设高速公路,要使高速公路可以连通所有村子同时成本最低。
输出路线中最长距离。
#include<stdio.h>#define INF 0xfffff#define max 500int map[max][max];int dis[max],n,Max;void prim();int min(int a,int b){return a>b?b:a;}int main(void){ int t,i,j; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) scanf("%d",&map[i][j]); } prim(); printf("%d\n",Max); } return 0;} void prim(){ int i,j,now; int minedge,minnode; for(i=1;i<=n;i++) dis[i]=INF; now=1; Max=0; for(i=1;i<n;i++) { dis[now]=-1; minedge=INF; for(j=1;j<=n;j++) { if(j!=now&&dis[j]>=0) { dis[j]=min(dis[j],map[now][j]); if(dis[j]<minedge) { minedge=dis[j]; minnode=j; } } } now=minnode; if(minedge>Max) Max=minedge; }}
- POJ 一 2485 Highways(最小生成树)
- POJ 2485 Highways (最小生成树)
- poj 2485 Highways (最小生成树)
- POJ 2485 Highways(最小生成树)
- 【POJ】-2485-Highways(最小生成树)
- POJ 2485 Highways(最小生成树)
- POJ 2485Highways(最小生成树)
- 【POJ 2485】Highways(最小生成树)
- POJ 2485 Highways【最小生成树】
- poj 2485Highways(最小生成树 Kruskal)
- poj 2485 Highways (最小生成树)
- poj 2485 Highways 最小生成树
- poj 2485 Highways prim最小生成树
- POJ 2485 Highways 最小生成树
- POJ 2485 Highways(最小生成树)
- POJ 2485 Highways 最小生成树
- poj 2485 Highways 最小生成树
- POJ 2485 Highways (最小生成树)
- Objective-C runtime之消息(二)
- 黑马学习笔记——“未能映射路径”解决方法
- 网页复制代码去行标
- 获取系统磁盘驱动器
- C++预编译头文件
- POJ 一 2485 Highways(最小生成树)
- Spring MVC中文件上传时的异常HttpRequest -> MultipartHttpServletRequest ClassCastException
- ios创建两色线性径向渐变扇形
- 总是弹出visual studio 实时调试器 三种解决办法
- MFC图片框中画的图形用CImage保存成多种格式
- 初探面向对象---抽象类和接口
- Hoj 3134 Xiaodai’s Budget Program
- 中文排序
- DELPHI 中的Delay函数,利用GetTickCount和Application.ProcessMessages构建