无坑,裸题。直接敲就恩那个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. ops

    consists several key projects separately stand-alone connected entities massive scalability massive ...

  2. maven编写主代码与测试代码

    3.2 编写主代码 项目主代码和测试代码不同,项目的主代码会被打包到最终的构件中(比如jar),而测试代码只在运行测试时用到,不会被打包.默认情况下,Maven假设项目主代码位于src/main/ja ...

  3. Button和ImageButton

    Button----button ImageButton----图片button 共同拥有特征: 都能够作为一个button产生点击事件 不同点 1. Button有text的属性.ImageButt ...

  4. Network 20Q--Q2 How does Google sell ad spaces?

    在使用Google搜索的时候会发现,搜索出来的页面除了在左边显示搜索结果以外,还会页面的右边推荐一些广告.那么Google是怎么从这些广告挣钱以及广告商可以通过Google广告获得什么利益呢? Goo ...

  5. [转]MVP模式开发

    转自:http://www.jianshu.com/p/f7ff18ac1c31 基于面向协议MVP模式下的软件设计-(iOS篇) 字数9196 阅读505 评论3 喜欢11 基于面向协议MVP模式下 ...

  6. HTTP 503 错误 – 服务不可用 (Service unavailable)

    介绍 因暂时超载或临时维护,您的 Web 服务器目前无法处理 HTTP 请求. 其含义是, 这是一个暂时情况,会有一些延误, 过 后将会得到缓解. 有些服务器在这种情况下也许干脆拒绝套接字(socke ...

  7. CAS单点登录原理以及debug跟踪登录流程

    CAS 原理和协议 基础模式 基础模式 SSO 访问流程主要有以下步骤: 1. 访问服务: SSO 客户端发送请求访问应用系统提供的服务资源. 2. 定向认证: SSO 客户端会重定向用户请求到 SS ...

  8. Visual C++基础知识(win32exe)

    1.Visual C++简称VC或者VC++ 是一个集成开发环境(编辑器+调试器+编译器) gcc---Linux和Unix的C++编译器 Vc----Windows的C++编译器 2.MFC(Mic ...

  9. GTD:是一种态度

    时间管理发展的四个阶段: 第一代理论着重利用便条与备忘录,在忙碌中调配时间与精力: 第二代理论强调行事历与日程表,反映出时间管理已注意到规划未来的重要: 第三代理论正是目前流行的优先级观念.也就是依据 ...

  10. js 16进制字符串互转

    /** * 16进制转换为字符串 * @param hex * @returns {*} */ function hexToString(hex) { var tmp = ''; if (hex.le ...