Highways(prim)
http://poj.org/problem?id=2485
此题是求最小生成树里的最大权值。prim算法:
#include<stdio.h>
#include<string.h>
const int maxn=;
const int INF = <<;
int map[maxn][maxn];
int dis[maxn],vis[maxn];
int n,maxm;
void prim()
{
int pos;
for (int i = ; i <= n; i ++)
{
dis[i] = map[][i];
}
vis[] = ;
for (int i = ; i <= n-; i ++)
{
int min = INF;
for (int j = ; j <= n; j ++)
{
if (!vis[j] && dis[j] < min)
{
min = dis[j];
pos = j;
}
}
if(min > maxm)
{
maxm = min;
}
vis[pos] = ;
for (int j = ; j <= n; j ++)
{
if (!vis[j] && dis[j] > map[pos][j])
dis[j] = map[pos][j];
}
}
}
void init()
{
maxm = -;
for (int i = ; i <= n; i ++)
{
for (int j = ; j <= n; j ++)
{
map[i][j] = INF;
}
map[i][i] = ;
vis[i] = ;
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
init();
for (int i = ; i <= n; i ++)
{
for (int j = ; j <= n; j ++)
{
scanf("%d",&map[i][j]);
}
}
prim();
printf("%d\n",maxm);
}
return ;
}
Highways(prim)的更多相关文章
- 快速切题 poj 2485 Highways prim算法+堆 不完全优化 难度:0
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23033 Accepted: 10612 Descri ...
- POJ1751 Highways(Prim)
Highways Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13182 Accepted: 3814 Speci ...
- POJ 2485 Highways (prim最小生成树)
对于终于生成的最小生成树中最长边所连接的两点来说 不存在更短的边使得该两点以不论什么方式联通 对于本题来说 最小生成树中的最长边的边长就是使整个图联通的最长边的边长 由此可知仅仅要对给出城市所抽象出的 ...
- Highways(prim & MST)
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23421 Accepted: 10826 Descri ...
- POJ 2485:Highways(最小生成树&&prim)
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21628 Accepted: 9970 Descrip ...
- (最小生成树 Prim) Highways --POJ --1751
链接: http://poj.org/problem?id=1751 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1150 ...
- Highways - poj 2485 (Prim 算法)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24383 Accepted: 11243 Description T ...
- Highways POJ 2485【Prim】
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- Highways POJ-1751 最小生成树 Prim算法
Highways POJ-1751 最小生成树 Prim算法 题意 有一个N个城市M条路的无向图,给你N个城市的坐标,然后现在该无向图已经有M条边了,问你还需要添加总长为多少的边能使得该无向图连通.输 ...
随机推荐
- WebAPI PUT,DELETE请求404
- 测试edit中数据是否合法
void XyModal::OnEnKillfocusEdit1() { // TODO: 在此添加控件通知处理程序代码 CString cText; GetDlgItemText(IDC_EDIT1 ...
- PAT_A1114#Family Property
Source: PAT A1114 Family Property (25 分) Description: This time, you are supposed to help us collect ...
- 内核调试-ftrace introduction
ftrace https://www.ibm.com/developerworks/cn/linux/l-cn-ftrace1/ https://www.ibm.com/developerworks/ ...
- swift--Xcode7 使用Alamofire框架发送HTTP请求报错
控制台打印的错误信息: Application Transport Security has blocked a cleartext HTTP (http://) resource load sinc ...
- 00_Rust安装及Hello World
Rust 官网: https://www.rust-lang.org 版本:nightly.beta.stable 如何设计语言的讨论:https://github.com/rust-lang/rfc ...
- How to start a pdf reader from a Linux command line?
Before you do this, you should be in a GOME or KDE environment, then type the following commands to ...
- 精彩的linux shell 命令
1. Star Wars (telnet) telnet是基于Telnet协议的远程登录客户端程序,经常用来远程登录服务器.除此还可以用它来观看星球大战: telnet towel.blinken ...
- PatentTips - Zero voltage processor sleep state
BACKGROUND Embodiments of the invention relate to the field of electronic systems and power manageme ...
- Javascript控制回车键进行表单(form)提交(转)
一.采用钩子事件去捕获 键盘事件有3个: keydown,keypress,keyup分别是按下,按着没上抬,上抬键盘 . $(document).keyup(function(event){ if( ...