hdu 1233

#include<stdio.h>
#include<algorithm>
using namespace std;
struct dis
{
int a, b, c;
} s[];
int cmp(dis x, dis y)
{
return x.c < y.c;
}
int father[];
int fsize[];
int findfather(int y)
{
int r = y;
while (r != father[r])
{
r = father[r];
}
return r;
}
int combine(int a, int b)
{
int fx = findfather(a);
int fy = findfather(b);
if (fx != fy)
{
if (fsize[fx] >= fsize[fy])
{
father[fy] = fx;
fsize[fx] += fsize[fy];
fsize[fy] = ;
}
else
{
father[fx] = fy;
fsize[fy] += fsize[fx];
fsize[fx] = ;
}
return ;
}
else
{
return ;
}
}
int main()
{
int t, i, n, sum, m;
while (~scanf("%d", &t), t)
{
n = t * (t - ) / ;
for (i = ; i <= t; i++)
{
fsize[i] = ;
father[i] = i;
}
for (i = ; i < n; i++)
{
scanf("%d%d%d", &s[i].a, &s[i].b, &s[i].c);
}
sort(s, s + n, cmp);
m = , sum = ;
for (i = ; i < n && m < t; i++)
{
if (combine(s[i].a, s[i].b))
{
m++;
sum += s[i].c;
}
}
printf("%d\n", sum);
}
return ;
}

最新文章

  1. 发布Live Writer代码着色插件CNBlogs.CodeHighlighter
  2. github上比较全的知识
  3. ASP.NET之Ajax系列(三)
  4. 怎么用ABBYY打开PDF文档
  5. do while 与while的区别!
  6. Android 字体颜色变化(点击)
  7. poj2196---Specialized Four-Digit Numbers
  8. 汉化Eclipse
  9. 海康&amp;大华&amp;DSS视频拉流-RTSP转RTMP多媒体播放技术
  10. CentOS配代理服务器
  11. Windows操作系统下搭建Git服务器和客户端。
  12. Laravel 学习笔记
  13. P2880 [USACO07JAN]平衡的阵容Balanced Lineup(RMQ的倍增模板)
  14. python-面向对象(绑定方法与非绑定方法)
  15. 2.匿名类,匿名类对象,private/protected/public关键字、abstract抽象类,抽象方法、final关键字的使用,多线程Thread类start方法原理
  16. Docker学习笔记之浅谈虚拟化和容器技术
  17. nc命令简介
  18. matplotlib01
  19. python numpy logic_and
  20. 生成带有表格的word附件和动态赋值

热门文章

  1. 【HANA系列】SAP HANA SQL获取字符串长度
  2. MATLAB灰色关联度分析
  3. C#编程 线程,任务和同步(2) 开启线程
  4. 【JulyEdu-Python基础】第 3 课:容器以及容器的访问使用
  5. Cannot get a NUMERIC value from a STRING cell? 已解决
  6. 解析之Apache解析
  7. 第六次java实验报告
  8. Hadoop三种架构介绍及搭建
  9. springBoot中tomcat默认端口修改
  10. LOJ526「LibreOJ β Round #4」子集