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个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要 ...
随机推荐
- luogu P1437 [HNOI2004]敲砖块
三角形向右对齐后 你想打掉一个砖块,那么你必须打掉右上方的三角形,前缀和维护 若是第i列若是k个,那么它右边的那一列至少选了k-1个 f[i][j][k] 表示从后向前选到第 i 列第j个一共打了k次 ...
- luogu P1195 口袋的天空
题目背景 小杉坐在教室里,透过口袋一样的窗户看口袋一样的天空. 有很多云飘在那里,看起来很漂亮,小杉想摘下那样美的几朵云,做成棉花糖. 题目描述 给你云朵的个数N,再给你M个关系,表示哪些云朵可以连在 ...
- 1.11(java学习笔记)封装
封装将内部细节封装起来,只暴露外部接口. 比如我们的电视就将复杂的内部线路用外壳封装起来,只留下外部按钮或遥控,用户只需要知道按钮或遥控的作用就可以,无需明白电视内部是如何工作. 而且封装也保障了安全 ...
- BZOJ 3864 Hero Meets Devil
题目大意 给定一个由AGCT组成的串\(t\), 求对于所有的\(L \in [1, |t|]\), 有多少个由AGCT组成的串\(s\)满足\(LCS(s, t) = L\). Solution 传 ...
- asp.net mvc 生成二维码
生成二维码,帮助类: using Gma.QrCodeNet.Encoding; using Gma.QrCodeNet.Encoding.Windows.Render; using System; ...
- 【转】三种方式在C++中调用matlab
C/C++调用Matlab 在工程实践中,C/C++调用Matlab 的方法主要有调用Matlab 计算引擎.包含m 文件转 换的C/C++文件,以及调用m文件生成的DLL 文件. 1 利用Mat ...
- Makefile文件的使用
编译程序: vi Makefile exe:a.c b.c gcc a.c b.c -o exe clean: rm exe 保存并退出: 这里exe:a.c b.c面的exe称为目标:a.c b.c ...
- PL/SQL Developer 显示中文乱码问题解决
PL/SQL Developer 显示中文乱码问题简单版本:首先,通过 select userenv('language') from dual;查询oracle服务器端的编码, 如为: AMERIC ...
- 用word2vec对语料进行训练
在Linux上安装好word2vec, 进入trunk文件夹,把分词后的语料文件放在trunk文件夹内,执行:./word2vec -train tt.txt -output vectors.bin ...
- 2017.6.29 移除再导入maven module到IDEA中时提示: Unable to proceed. Nothing found to import.
解决办法来自:https://stackoverflow.com/questions/18278016/re-importing-modules-into-intellij 场景: 将其中一个modu ...