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 ...
随机推荐
- Linux批量重命名文件
五种方法实现Linux批量重命名文件 Linux批量重命名文件是指对某些特定的文件统一进行重新命名,以改变原来一批文件的名称,这里介绍五种方法来实现. Linux批量重命名文件会涉及到改变一个字母.改 ...
- BZOJ 1087 互不侵犯King (位运算)
题解:首先,这道题可以用位运算来表示每一行的状态,同八皇后的搜索方法,然后对于限制条件不相互攻击,则只需将新加入的一行左右移动与上一行相&,若是0则互不攻击,方案可行.对于每种方案,则用递推来 ...
- Oracle 动态查询,EXECUTE IMMEDIATE select into使用方法
create or replace procedure TEST_TABLE is l_table_name varchar2(50); query_stat varchar2(100); l_zyq ...
- Android多线程断点续传下载
这个月接到一个项目.要写一个像360助手一样的对于软件管理的APP:当中.遇到了一个问题:多线程断点下载 这个 ,因为之前没有写过这方面的应用功能.所以.不免要自学了. 然后就在各个昂站上收索并整理了 ...
- Qt5官方demo分析集11——Qt Quick Particles Examples - Affectors
在这个系列中的所有文章都可以在这里查看http://blog.csdn.net/cloud_castle/article/category/2123873 接上文Qt5官方demo解析集10--Qt ...
- 几种经典排序算法的JS实现
一.冒泡排序 function BubbleSort(array) { var length = array.length; for (var i = length - 1; i > 0; i- ...
- 【JAVA】修改项目包名
从最后一层开始修改,一步步往上递增修改.
- sdl2-2.04 读取位图并显示
// sdl2_win32.cpp : Defines the entry point for the console application.//// 假定SDL的库文件和头文件和VC的工程文件在一 ...
- leetcode 211. Add and Search Word - Data structure design Trie树
题目链接 写一个数据结构, 支持两种操作. 加入一个字符串, 查找一个字符串是否存在.查找的时候, '.'可以代表任意一个字符. 显然是Trie树, 添加就是正常的添加, 查找的时候只要dfs查找就可 ...
- Python网络编程——设备名和IPv4地址
1.快速查看主机名和对应的IP地址小程序 import socket def print_machine_info(): # 定义print_machine_info()类 host_name = s ...