POJ 2485:Highways(最小生成树&&prim)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 21628 | Accepted: 9970 |
Description
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.
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
这题写的真烦。
。
各种不知道的莫名其妙的
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath> using namespace std; const int INF=1000000000;
const int N=510;
int map[N][N];
int vis[N];
int ans;
int dis[N]; void prim(int n)//prim求最小生成树
{
memset(vis, 0, sizeof(vis));
for(int i=1; i<=n; i++)
{
dis[i] = INF;
}
dis[1] = 0;
ans = 0;
for(int i=1; i<=n; i++)
{
int temp = INF, k = 0;
for(int j=1; j<=n; j++)
{
if(!vis[j] && dis[j]<temp)
{
temp = dis[j];
k = j;
}
}
vis[k] = true;
if(ans<temp) ans = temp;
for(int j=1; j<=n; j++)
{
if(!vis[j] && dis[j]>map[k][j])
{
dis[j] = map[k][j];
}
}
}
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n;
scanf("%d", &n);
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
scanf("%d", &map[i][j]);
}
}
prim(n);
printf("%d\n", ans);
}
return 0;
}
错误。。
版权声明:本文博客原创文章,博客,未经同意,不得转载。
POJ 2485:Highways(最小生成树&&prim)的更多相关文章
- POJ 2485 Highways(最小生成树+ 输出该最小生成树里的最长的边权)
...
- poj 2485 Highways 最小生成树
点击打开链接 Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19004 Accepted: 8815 ...
- POJ 2485 Highways 最小生成树 (Kruskal)
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- poj 2485 Highways (最小生成树)
链接:poj 2485 题意:输入n个城镇相互之间的距离,输出将n个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要 ...
- poj 2485 Highways
题目连接 http://poj.org/problem?id=2485 Highways Description The island nation of Flatopia is perfectly ...
- POJ 2485 Highways (prim最小生成树)
对于终于生成的最小生成树中最长边所连接的两点来说 不存在更短的边使得该两点以不论什么方式联通 对于本题来说 最小生成树中的最长边的边长就是使整个图联通的最长边的边长 由此可知仅仅要对给出城市所抽象出的 ...
- POJ 2485 Highways【最小生成树最大权——简单模板】
链接: http://poj.org/problem?id=2485 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ 2485 Highways( 最小生成树)
题目链接 Description The islandnation of Flatopia is perfectly flat. Unfortunately, Flatopia has no publ ...
- POJ 1751 Highways(最小生成树Prim普里姆,输出边)
题目链接:点击打开链接 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has ...
- 快速切题 poj 2485 Highways prim算法+堆 不完全优化 难度:0
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23033 Accepted: 10612 Descri ...
随机推荐
- JavaEE Tutorials (9) - 运行持久化示例
9.1order应用118 9.1.1order应用中的实体关系119 9.1.2order应用中的主键121 9.1.3实体映射到多个数据库表125 9.1.4order应用中的层叠操作125 9. ...
- Mark Russinovich 的博客:Windows Azure 主机更新:原因、时间和方式
Mark Russinovich的技术博客涵盖 Windows故障排除.技术和安全等主题. Windows Azure主机更新:原因.时间和方式 Windows Azure的计算平台(其中包括 ...
- hdoj 1824 Let's go home(2-SAT)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1824 思路分析:该问题为2-SAT问题:需要注意逻辑推理的等价性: (1)题目第一个条件:每一个队或者 ...
- 08.net网站开发(前端):5.jQuery
开发网站肯定要会JS,嫌代码太难看难学那至少要学会jQuery.当然我见过有些项目纯用服务端控件也是能做出来的,但我相信,那些碰到复杂的需求的话肯定很棘手的.jQuery是对JS和DOM的封装,少量代 ...
- UVA - 12230 Crossing Rivers (期望)
Description You live in a village but work in another village. You decided to follow the straight pa ...
- Sql语句之select 5种查询
select 5种子句:注意顺序where / group by /having / order by / limit / 清空表中的数据:truncate 表名: 导入表结构(不含数据): crea ...
- Sass入门——简介+语法格式及编译调试
本文来自慕课网大漠. Sass简介 Sass和SCSS区别 1.后缀名不同,很好理解 2.Sass以严格的缩进语法规则书写,不带大括号和分号:而SCSS的语法规则和CSS的语法很类似. Sass: $ ...
- 带参数的存储过程和标量Function
在SQL Server中,我们通常会使用NEWID(),GETDATE(),等一些数据库函数,这些函数是很有帮助的,然后数据库也能够让我们自己写函数,即Function,下面简单说说Function的 ...
- Unity 对象池 生产 保存
Unity对象池主要是保存那些常用的物体,避免他们在不断销毁和创造中损坏性能. 主要思路为:创造物体时,判断是否存在,如果存在则调用并使其显示.如果不存在则创造一个新的. 当销毁时,调用协程延时隐藏物 ...
- jbpmAPI-1
1.1. What is jBPM? jBPM是一个灵活的业务流程管理(BPM)套件.它是轻量级的,完全开源Apache许可下(分布式),用Java编写的.它允许您模型.执行和监控业务流程的整个生命周 ...