#include<iostream>
#include<algorithm>
using namespace std; const int maxn = ;
int n, m;
int fa[];
struct node
{
int x, y;
int cost;
}arr[maxn]; void init()
{
for (int i = ; i <= maxn; i++)
{
fa[i] = i;
}
} int find(int x)
{
if (x != fa[x])
{
return find(fa[x]);
}
else
return fa[x];
} bool cmp(node a, node b)
{
return a.cost<b.cost;
} int main()
{
char c1, c2;
int k, c;
while (cin >> n)
{
if (n == ) break;
int j = ; //表示边的数量
init();
for (int i = ; i<n; i++)
{
cin >> c1 >> k;
while (k--)
{
cin >> c2 >> c;
arr[j].x = c1 - 'A';
arr[j].y = c2 - 'A';
arr[j].cost = c;
j++;
}
}
sort(arr, arr + j, cmp); //排序
int ans = ;
for (int i = ; i<j; i++)
{
int fx, fy;
fx = find(arr[i].x);
fy = find(arr[i].y);
if (fx != fy)
{
ans += arr[i].cost;
fa[fy] = fx;
}
}
cout << ans << endl;
}
return ;
}

hdu1301 Jungle Roads 基础最小生成树的更多相关文章

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

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

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

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

  3. POJ 1251 Jungle Roads(最小生成树)

    题意  有n个村子  输入n  然后n-1行先输入村子的序号和与该村子相连的村子数t  后面依次输入t组s和tt s为村子序号 tt为与当前村子的距离  求链接全部村子的最短路径 还是裸的最小生成树咯 ...

  4. HDU1301 Jungle Roads

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

  5. POJ1251 Jungle Roads 【最小生成树Prim】

    Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19536   Accepted: 8970 Des ...

  6. Jungle Roads(最小生成树)

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

  7. hdu1301 Jungle Roads 最小生成树

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

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

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

  9. POJ 1251 Jungle Roads (最小生成树)

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

随机推荐

  1. Objective-C面向对象-对象和类

    文章都是先由本人个人博客:孙占兴:www.teilim.com,先更新,随后CSDN博客才会更新,掌握第一动态请关注本人主站. 原文链接:http://www.teilim.com/objective ...

  2. onedrive实现excel在线编辑 online excel

    1.首先用火狐浏览器或者谷歌浏览器登录 https://onedrive.live.com 2.注冊邮箱账户信息 3.在邮箱激活账户信息 4.登录进去.点击我的账户,点击左側文件树.点选上载,将文件上 ...

  3. 博客系统-评论or评论树

    url配置 url(r'^commentTree/(?P<article_id>\d+)/',views.commentTree), url(r'^(?P<username>. ...

  4. PostgreSQL 源码解读 node的模拟实现

      node的实现是PostgreSQL的查询解析的基础,实现的关键是两个宏,makeNode和newNode.其他节点继承自Node节点,如果增加新的结构体,需要添加NodeTag中添加对应的枚举值 ...

  5. $.ajax 使用详解

    Jquery在异步提交方面封装的很好,直接用AJAX非常麻烦,Jquery大大简化了我们的操作. $.post.$.get是一些简单的方法,如果要处理复杂的逻辑,还是需要用到jQuery.ajax() ...

  6. Vijos P1389婚礼上的小杉

    背景 小杉的幻想来到了经典日剧<求婚大作战>的场景里……他正在婚礼上看幻灯片,一边看着可爱的新娘长泽雅美,一边想,如果能再来一次就好了(-.-干嘛幻想这么郁闷的场景……). 小杉身为新一代 ...

  7. I2S

    音频数据传输而制定: Inter—IC Sound : 单线 时钟和数据一条线,时分复用: 标准的I2S总线电缆是由3根串行导线组成的:1根是时分多路复用(简称TDM)数据线:1根是字选择线:1根是时 ...

  8. expect的安装与使用

    expect的安装与使用 是什么 expect 是用来进行自动化控制和测试的工具.主要是和交互式软件telnet ftp ssh 等进行自动化的交互. 如何安装 1.检测是否安装 ls /usr/bi ...

  9. STL Algorithms 之 unique

    C++的文档中说,STL中的unique是类似于这样实现的: template <class ForwardIterator> ForwardIterator unique ( Forwa ...

  10. maven实战(3)-- dependency <classifier>的使用

    Maven 的classifier的作用 转自:http://blog.csdn.net/lovingprince/article/details/5894459 直接看一个例子,maven中要引入j ...