http://acm.hdu.edu.cn/showproblem.php?pid=1301

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 500
using namespace std;
const int inf=<<; int g[maxn][maxn];
int dis[maxn];
bool vis[maxn];
int n,x,mm,sum;
char ch,ch1; void prim()
{
memset(vis,false,sizeof(vis));
for(int i=; i<n; i++) dis[i]=g[][i];
dis[]=;
vis[]=true;
for(int i=; i<n; i++)
{
int m=inf,x;
for(int y=; y<n; y++) if(!vis[y]&&dis[y]<m) m=dis[x=y];
vis[x]=true;
sum+=m;
for(int y=; y<n; y++) if(!vis[y]&&dis[y]>g[x][y]) dis[y]=g[x][y];
}
} int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
getchar();
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
if(i==j) g[i][j]=;
else g[i][j]=inf;
}
}
for(int i=; i<=n-; i++)
{
scanf("%c %d%*c",&ch,&x);
for(int j=; j<x; j++)
{
scanf("%c %d%*c",&ch1,&mm);
g[ch-'A'][ch1-'A']=g[ch1-'A'][ch-'A']=mm;
}
}
sum=;
prim();
printf("%d\n",sum);
}
return ;
}

hdu 1301 Jungle Roads的更多相关文章

  1. POJ 1251 && HDU 1301 Jungle Roads (最小生成树)

    Jungle Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/A http://acm.hust.edu.cn/vju ...

  2. hdu 1301 Jungle Roads 最小生成树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 The Head Elder of the tropical island of Lagrish ...

  3. Hdu 1301 Jungle Roads (最小生成树)

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=1301 很明显,这是一道“赤裸裸”的最小生成树的问题: 我这里采用了Kruskal算法,当然用Prim算法也 ...

  4. hdu 1301 Jungle Roads krusckal,最小生成树,并查集

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

  5. POJ 1251 & HDU 1301 Jungle Roads

    题目: Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign ...

  6. HDU 1301 Jungle Roads (最小生成树,基础题,模版解释)——同 poj 1251 Jungle Roads

    双向边,基础题,最小生成树   题目 同题目     #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<stri ...

  7. POJ 1251 + HDU 1301 Jungle Roads 【最小生成树】

    题解 这是一道裸的最小生成树题,拿来练手,题目就不放了 个人理解  Prim有些类似最短路和贪心,不断找距当前点最小距离的点 Kruskal类似于并查集,不断找最小的边,如果不是一棵树的节点就合并为一 ...

  8. 最小生成树 || HDU 1301 Jungle Roads

    裸的最小生成树 输入很蓝瘦 **并查集 int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } 找到x在并查集里的根结点,如果 ...

  9. HDOJ 1301 Jungle Roads

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 //HDOJ1301 #include<iostream>#include<c ...

随机推荐

  1. 一道面试题与Java位操作 和 BitSet 库的使用

    前一段时间在网上看到这样一道面试题: 有个老的手机短信程序,由于当时的手机CPU,内存都很烂.所以这个短信程序只能记住256条短信,多了就删了. 每个短信有个唯一的ID,在0到255之间.当然用户可能 ...

  2. 最牛逼的的shell命令

    参考 远程diff [root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA/tools/iperf] #ssh ahao.mah@dnstest02.tbc c ...

  3. Android开发编码规范(自用)

    转载请注明本文出自Cym的博客(http://blog.csdn.net/cym492224103),谢谢支持!   Android开发编码规范 目的及指导原则 目的 统一规范 Eclipse编辑环境 ...

  4. vsftpd安装、多用户配置

    1.vsftpd安装 rpm -ivh vsftpd 2.2.2 11.el6_4.1.x86_x64.rpm 2.添加ftp用户 添加ftp用户组 groupadd ftpg 添加ftp用户 use ...

  5. iOS项目名称、版本号与屏幕分辨率

    iOS的版本号,一个叫做Version,一个叫做Build,这两个值都可以在Xcode 中选中target,点击“Summary”后看到. Version在plist文件中的key是“CFBundle ...

  6. C#多线程实践——线程同步

    下面的表格列展了.NET对协调或同步线程动作的可用的工具:                       简易阻止方法 构成 目的 Sleep 阻止给定的时间周期 Join 等待另一个线程完成      ...

  7. Sql时间函数

    一.sql server日期时间函数 Sql Server中的日期与时间函数  1.  当前系统日期.时间   select getdate()    2. dateadd  在向指定日期加上一段时间 ...

  8. POJ 1151 - Atlantis 线段树+扫描线..

    离散化: 将所有的x轴坐标存在一个数组里..排序.当进入一条线段时..通过二分的方式确定其左右点对应的离散值... 扫描线..可以看成一根平行于x轴的直线..至y=0开始往上扫..直到扫出最后一条平行 ...

  9. 使用 c# 调用进程相关开发

    最近在维护公司的以前项目中发现,使用到了进程相关知识.现在将此总结,以备后面查看复习. 一.进程查看器     程序在运行的时候,操作系统就会为其分配一个进程.那么进程到底是什么东西呢? 实际上,进程 ...

  10. jQuery插件实现select下拉框左右选择_交换内容(multiselect2side)

    效果图: 使用jQuery插件---multiselect2side做法: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitio ...