无坑,裸题。直接敲就恩那个AC。

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <numeric> #define typec int
using namespace std; const int V = ;
const int inf = 0xffff;
int vis[V]; typec lowc[V], Map[V][V]; typec prim (typec cost[][V], int n) {
int i, j, p;
typec minc, res = ;
memset(vis, , sizeof(vis));
vis[] = ;
for (int i = ; i < n; ++ i) lowc[i] = cost[][i];
for (int i = ; i < n; ++ i) {
minc = inf; p = -;
for (j = ; j < n; ++ j) {
if ( == vis[j] && minc > lowc[j]) {
minc = lowc[j]; p = j;
}
}
if (inf == minc) return -;
res += minc; vis[p] = ;
for (j = ; j < n; ++ j) {
if ( == vis[j] && lowc[j] > cost[p][j])
lowc[j] = cost[p][j];
}
}
return res;
} int main () {
int n;
while (~scanf("%d", &n) && n) {
for (int i = ; i < V; ++ i) {
for (int j = ; j < V; ++ j) {
if (i == j) Map[i][j] = ;
else Map[i][j] = inf;
}
}
for (int i = ; i < n * (n - ) / ; ++i) {
int x, y, c; scanf("%d%d%d", &x, &y, &c);
if (x == y) continue;
Map[x - ][y - ] = Map[y - ][x - ] = min(Map[x - ][y - ], c);
}
cout << prim(Map, n) << endl;
}
return ;
}

【HDU1233】还是畅通工程(MST基础题)的更多相关文章

  1. hdu-1233 还是畅通工程---MST模板

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1233 题目大意: 求MST最小生成树 解题思路: Prim算法直接套即可 #include<b ...

  2. HDU-1233 还是畅通工程

    Problem Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能 ...

  3. hdu 1233 - 还是畅通工程(MST)

    还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  4. hdu 1863 - 畅通工程(MST)

    畅通工程 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. 还是畅通工程(MST)

    还是畅通工程 Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  6. HDU-1233 还是畅通工程 (prim 算法求最小生成树)

    prim 算法求最小生成树 还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  7. HDU1233 还是畅通工程 2017-04-12 19:49 64人阅读 评论(0) 收藏

    还是畅通工程 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  8. hdu1233 继续畅通工程 (最小生成树——并查集)

    还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  9. 最小生成树: HDU1233还是畅通工程

    还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  10. hdu1233还是畅通工程

    还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

随机推荐

  1. Android去除系统自带动画的两种方法

    方法一: 在startActivity()或者finish()后紧跟调用: ((Activity) mContext).overridePendingTransition(0, 0); 方法二: 在一 ...

  2. Go--包引用介绍

    最近在学习Go编程,本文简单的叙述如何在Go编程中使用包(包管理). 和其他大多数语言一样,Go也存在包,并使用package关键字定义一个包.首先介绍在程序中如何引入包,引入包有以下几种方式: 1. ...

  3. 最简单的内核模块hello world

    [root@rt2m09617.sqa.tbc /home/ahao.mah/main] #cat hello.c // Defining __KERNEL__ and MODULE allows u ...

  4. Spring MVC + Spring MongoDB + Querydsl 通过maven整合实例

    效果图 一共3个页面:注册页,欢迎页,用户列表页 很简单的例子,主要是为了把流程走通,没有各种验证. 注册页: 欢迎页: 用户列表页: 源码地址 https://github.com/lemonbar ...

  5. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 解决办法

    Maven install失败 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (d ...

  6. [原创作品] RequireJs入门进阶教程

    最近我发现RSS采集数据是个很好玩的东西,就是可以直接把别人的数据放在自己的网站上.如果网友们在其他地方发现这篇文章,还是来博客园看吧(http://zhutty.cnblogs.com).这样代码比 ...

  7. 操作系统——IO缓存技术

    一.为什么引入缓存技术 为了解决cpu速度和外部设备速度不匹配的问题. 降低了io对cpu的中断的次数.每进行一次IO设备的时间都非常长,所以把数据先放入缓冲区,再进行IO操作. 二.缓冲技术的实现 ...

  8. _js day10

  9. Fantageek翻译系列之《使用Autolayout显示变化高度的UITableViewCell》

    这篇博客主要在于,解释如何通过仅仅使用Autolayout很很少的代码,显示高度不同的Cell.虽然标题说的是TableView,但是CollectionView同样适合.但是,这种方法只使用iOS7 ...

  10. C# XML,XmlDocument简单操作实例

    private static string _Store = LocalPathHelper.CurrentSolutionPath + "/data/bookstore.xml" ...