爽爆。史上个人最快MST的记录7分40s。。一次A。

 #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <numeric> #define typec int
using namespace std; const typec inf = 0xffff;
const int V = ;
int vis[V]; typec lowc[V];
int Map[V][V]; typec prim (typec cost[][V], int n) {
int i, j, p;
typec minc, res = ;
memset(vis, , sizeof (vis));
vis[] = ;
for (i = ; i < n; ++ i) lowc[i] = cost[][i];
for (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)) {
if (n == ) break;
for (int i = ; i < n; ++ i) {
for (int j = ;j < n; ++ j) {
if (i == j) Map[i][j] = ;
else Map[i][j] = inf;
}
} for (int i = ; i < n - ; ++ i) {
char s_c; int e_n;
cin >> s_c >> e_n;
for (int j = ; j < e_n; ++ j) {
char e_c; int w;
cin >> e_c >> w;
Map[s_c - 'A'][e_c - 'A'] = Map[e_c - 'A'][s_c - 'A'] = min(Map[s_c - 'A'][e_c - 'A'], w);
}
} cout << prim(Map, n) << endl;
}
return ;
}

【HDU1301】Jungle Roads(MST基础题)的更多相关文章

  1. HDU1301 Jungle Roads

    Jungle Roads The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign ai ...

  2. HDU-1301 Jungle Roads(最小生成树[Prim])

    Jungle Roads Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  3. 【HDU1102】Constructing Roads(MST基础题)

    最小生成树水题.prim一次AC #include <iostream> #include <cstring> #include <cstdlib> #includ ...

  4. hdu1301 Jungle Roads 基础最小生成树

    #include<iostream> #include<algorithm> using namespace std; ; int n, m; ]; struct node { ...

  5. hdu1301 Jungle Roads 最小生成树

    The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was s ...

  6. 【HDU1162】Eddy's picture(MST基础题)

    很基础的点坐标MST,一不留神就AC了, - - !! #include <iostream> #include <cstring> #include <cstdlib& ...

  7. HDU1301 Jungle Roads(Kruskal)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  8. 【HDU1879】继续畅通工程(MST基础题)

    真心大水题...不多说. #include <iostream> #include <cstring> #include <cstdlib> #include &l ...

  9. 【HDU1233】还是畅通工程(MST基础题)

    无坑,裸题.直接敲就恩那个AC. #include <iostream> #include <cstring> #include <cstdio> #include ...

随机推荐

  1. 如何从Linux系统中获取带宽、流量网络数据

    引入 国外的云主机厂商,例如AWS提供的网络数据是以流量为单位的,例如下面的图片: 从上图来看,其取值方式为 每隔5分钟取值1次,(每次)每个点显示为1分钟内的流量字节数(Bytes) 带宽与流量 我 ...

  2. js 获取input file路径改变图像地址

    html代码 <img id="newImage" alt="100x100" src="__PUBLIC__/img/1.jpg" ...

  3. python RabbitMQ队列使用(入门篇)

    ---恢复内容开始--- python RabbitMQ队列使用 关于python的queue介绍 关于python的队列,内置的有两种,一种是线程queue,另一种是进程queue,但是这两种que ...

  4. js高级程序设计(第三版)学习笔记(第一版)

    ecma:欧洲计算机制造商协会iso/iec:国际标准化和国际电工委员会 dom级别(10*)文档对象模型1:DOM核心(映射基于xml文档)与dom html(在dom核心基础上)2:对鼠标,事件, ...

  5. maven-Android项目环境搭建

    参考:http://blog.csdn.net/earbao/article/details/40741051 android maven环境搭建: 1.Maven的版本要求3.1.1 2.设置AND ...

  6. Live555 实战之框架简单介绍

    作者:咕唧咕唧liukun321 来自:http://blog.csdn.net/liukun321 上一篇文章简要介绍了怎样以共享库的方式交叉编译Live555,今天再来介绍live源代码框架. 先 ...

  7. Spring redirect直接返回项目根文件夹

    return "redirect:/";

  8. Gunplot 命令大全

    在linux命令提示符下运行gnuplot命令启动,输入quit或q或exit退出. plot命令 gnuplot> plot sin(x) with line linetype 3 linew ...

  9. C# KeyValuePair<TKey,TValue>与Container

    KeyValuePair<TKey,TValue>  KeyValuePair<TKey,TValue>是一个结构体,相当于C#一个Map类型的对象,可以通过它记录一个键/值对 ...

  10. (转)window.location.search的用法

    location.search是从当前URL的?号开始的字符串如:http://www.51js.com/viewthread.php?tid=22720它的search就是?tid=22720 通过 ...