题目传送门

 /*
此题为:HDOJ 1233 + HDOJ 1232
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int MAX_N = + ;
int pre[MAX_N];
int tot;
int sum;
struct NODE
{
int x, y;
int len;
}node[MAX_N]; int find(int root)
{
int son, tmp;
son = root; while (root != pre[root])
{
root = pre[root];
}
while (son != root)
{
tmp = pre[son];
pre[son] = root;
son = tmp;
} return root;
} bool cmp(NODE a, NODE b)
{
return a.len < b.len;
} int main(void) //HDOJ 1863 畅通工程
{
//freopen ("inC.txt", "r", stdin);
int n, m; //n路, m村庄 while (~scanf ("%d%d", &n, &m) && n)
{
tot = m - ;
for (int i=; i<=m; ++i)
{
pre[i] = i;
}
for (int i=; i<=n; ++i)
{
scanf ("%d%d%d", &node[i].x, &node[i].y, &node[i].len);
}
sort (node+, node++n, cmp);
sum = ;
for (int i=; i<=n; ++i)
{
int a, b;
a = find (node[i].x);
b = find (node[i].y);
if (a != b)
{
pre[a] = b;
sum += node[i].len;
--tot;
}
}
if (tot == )
printf ("%d\n", sum);
else
puts ("?");
}
}

最新文章

  1. flash开发几个问题
  2. Change Git Default Editor in Windows
  3. Tomcat 配置 HTTPS双向认证
  4. shutdown命令
  5. mysql高可用方案比较
  6. Linux(Centos)全自动异地备份数据(WEB+Mysql)
  7. 几个好用的截取字符串的php函数分享
  8. AttributeError: &#39;int&#39; object has no attribute &#39;log&#39;
  9. Android UI技巧(一)——Android中伸缩自如的9patch图片切法,没有美工自给自足
  10. 【TLV】非递归TLV数据解析
  11. CAS SSO单点登录框架学习
  12. 牛客多校第二场A run(基础DP)
  13. HDU1730 Northcott Game 尼姆博弈
  14. Selenium清空列数据
  15. 沉淀再出发:关于IntelliJ IDEA使用的一些总结
  16. 测试面试必会sql(1)
  17. HDU 4665 Mutiples on a circle (圆环DP)
  18. jcabanillas/yii2-inspinia-asset composert 安装失败
  19. 20162327实验一Java开发环境的熟悉实验报告
  20. vloatile总结与synchronized对比

热门文章

  1. scrollTo(String text) and scrollToExact(String text) method of Android Driver not working
  2. ajax的异步操作及页面重定向跳转
  3. VC断点失败的原因之中的一个
  4. Bootstrap progress-bar
  5. 织梦dedecms页面中增加二维码功能的实现方法
  6. String bulit-in function
  7. poj 1094 Sorting It All Out 解题报告
  8. Pycharm中如何安装python库
  9. [SDOI2016] 模式字符串 (BZOJ4598 &amp; VIJOS1995)
  10. 「BZOJ3438」小M的作物(最小割