Highways - poj 2485 (Prim 算法)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 24383 | Accepted: 11243 |
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 <stdio.h>
#define INF 65537;
int map[][];
int vis[];
int dis[];
int n;
int Prim(){
for(int i=;i<n;i++){
vis[i]=;
dis[i]=INF;
}
dis[]=;
for(int i=;i<n;i++){
int p;
int mine=INF;
for(int j=;j<n;j++){
if(!vis[j]&&mine>dis[j]){
p=j;
mine=dis[j];
}
}
vis[p]=;
for(int j=;j<n;j++){
if(!vis[j]&&dis[j]>map[p][j])
dis[j]=map[p][j];
}
}
int maxe=;
for(int i=;i<n;i++){
if(maxe<dis[i])
maxe=dis[i];
}
return maxe;
}
int main() { int num;
scanf("%d",&num);
for(int i=;i<num;i++){
scanf("%d",&n);
for(int j=;j<n;j++){
for(int k=;k<n;k++){
scanf("%d",&map[j][k]);
}
}
int maxe=Prim();
printf("%d\n",maxe);
}
return ;
}
Highways - poj 2485 (Prim 算法)的更多相关文章
- Highways POJ-1751 最小生成树 Prim算法
Highways POJ-1751 最小生成树 Prim算法 题意 有一个N个城市M条路的无向图,给你N个城市的坐标,然后现在该无向图已经有M条边了,问你还需要添加总长为多少的边能使得该无向图连通.输 ...
- Highways POJ 2485【Prim】
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- Highways poj 2485
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- poj 2485 (kruskal算法)
/*kruskal算法*/ #include <iostream> //#include <fstream> #include <algorithm> using ...
- Agri-Net - poj 1258 (Prim 算法)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44373 Accepted: 18127 Description F ...
- Truck History - poj 1789 (Prim 算法)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20884 Accepted: 8075 Description Ad ...
- POJ 2485 Prim 找最长的边
A国没有高速公路,因此A国的交通很困难.政府意识到了这个问题并且计划建造一些高速公路,以至于可以在不离开高速公路的情况下在任意两座城镇之间行驶. A国的城镇编号为1到N, 每条高速公路连接这两个城镇, ...
- 【POJ 2485】Highways(Prim最小生成树)
题目 Prim算法:任选一个点,加入集合,找出和它最近的点,加入集合,然后用加入集合的点去更新其它点的最近距离......这题求最小生成树最大的边,于是每次更新一下最大边. #include < ...
- poj 2485 Highways (最小生成树)
链接:poj 2485 题意:输入n个城镇相互之间的距离,输出将n个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要 ...
随机推荐
- socket 和 webservice 的区别和比较
时间紧迫,我就直奔主题. 目前需要说服客户使用webservice 而不是socket. 我觉得要先分别解释下什么是socket 什么是webservice..这个要我该怎么说才比较形象,让人一定就明 ...
- JD
General Description: The role is responsible for China COE Operations Team’s data and cost analysis, ...
- luogu P1821 [USACO07FEB]银牛派对Silver Cow Party
题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the b ...
- Listener监听器笔记1
1.常用的Web事件监听器接口: 1.ServletContextListener:用于监听Web应用的启动和关闭. 2.ServletContextAttributeListener:用于监听Ser ...
- 一次PHP面试经历
9月9号,去了一家朋友的公司参加面试,然后就被直接吊打了,问的许多问题居然是我压根没有关心过的,看起来只在高层搞框架不行啊,还是得自己造个轮子试试,下面回顾一下问到的问题和我自己找到的一些答案. fi ...
- nginx -- 启动, 重启, 关闭
Nginx的启动.停止与重启 重启: nginx -s reload 启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin] ...
- mysql关于数据量大的时候分页分批处理
前几天遇到一个问题是,数据库一开始有24W是信息,需要取出来,进行下载到excel中.一开始遇到的问题是,excel表格行只有65535条行数,远远不够,有人说了很多其他解决方式,为了快速开发我就直接 ...
- 重新认识被人遗忘的HTTP头注入
前言 注入类漏洞经久不衰,多年保持在owasp Top 10的首位.今天就聊聊那些被人遗忘的http头注入.用简单的实际代码进行演示,让每个人更深刻的去认识该漏洞. HOST注入 在以往http1.0 ...
- eclipse显示包的层次关系
如何在eclipse中显示包的层次关系呢?如下图所示
- ubuntu 备份清理tomcat日志,并且删除七天之前的日志
创建文件clear_tomcat_log.sh #!/bin/bash logs_paths[0]="app_tomcat7_8080"; logs_paths[1]=" ...