Jungle Roads hdu1301
来源:互联网 发布:风暴大陆战盾进阶数据 编辑:程序博客网 时间:2024/05/22 08:02
http://acm.hdu.edu.cn/showproblem.php?pid=1301
#include<iostream>//有是一个纯最小生成树的问题 ,一开始题目没有看了,看懂了,原来是这么简单的
#include<algorithm>//题意:输入一个n,n=0时break 在输入n-1行 每行输入大写字母表示村庄和组数k 在输入k行一个字母表示与这个村庄
#include<cmath> //相连和一个数字表示修路的费用,输入连通全部村庄的最小值
#include<cstdio>
using namespace std;
int s[500];
struct stu
{
// char v[2];
int x;
int y;
int dis;
} df[100];
int cmp(stu a, stu b)
{
return a.dis < b.dis ;
}
int find (int a)
{
int r = a;
while(r != s[r])
r = s[r];
return r;
}
void merge(int a, int b)
{
if(a > b )
s[a] = b;
else
s[b] = a;
}
int main()
{
int n, m, distance, j, count, k, i;
char str[2],str1[2];
while(scanf("%d", &n) != EOF && n != 0)
{
count = 0;
for(i = 1 ; i < n ;i++)
{
scanf("%s%d", str, &m);
while(m--)
{
scanf("%s%d",str1, &k);
df[count].x = (int)(str[0] - 64);
df[count].y = (int)(str1[0] - 64);
df[count].dis = k;
count++;
}
}
sort(df, df + count, cmp);
distance = 0;
for(i = 1; i<= 500; i++)
s[i] = i;
for(i = 0; i < count; i++)
{
int a = find(df[i].x);
int b = find(df[i].y);
if(a != b)
{
distance += df[i].dis;
merge(a, b);
}
}
printf("%d/n",distance);
}
}
- Jungle Roads hdu1301
- hdu1301 Jungle Roads
- HDU1301-Jungle Roads
- Jungle Roads hdu1301 Prim
- hdu1301 Jungle Roads
- HDU1301--Jungle Roads
- hdu1301 Jungle Roads (prim)
- hdu1301 Jungle Roads
- HDU1301 Jungle Roads【Prim】
- HDU1301---Jungle Roads
- HDU1301 Jungle Roads
- hdu1301 Jungle Roads
- HDU1301-Jungle Roads
- HDU1301&&POJ1251 Jungle Roads
- HDU1301 Jungle Roads
- hdu1301 Jungle Roads(kruskal 备忘)
- HDU1301:Jungle Roads(prime)
- hdu1301——Jungle Roads
- JAVA缓存的实现
- 2.6.27内核 netlink socket实现内核和用户的通信
- 2010の三月24
- symbian如何禁止屏幕旋转
- goto 与 start with ... connect by prior [nocyle]
- Jungle Roads hdu1301
- QQ天气预报分析
- 优秀论文的要素
- symbian开发总
- what's delegate in .net?
- C
- Linklabel控件的使用
- 篮球飞人
- ORA-27061: skgfospo: waiting for async I/Os failed