#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std; const int maxn = ;
int n, m;
struct node
{
int u, v, c;
}g[maxn];
long long ans;
int fa[maxn];
int ff[maxn];
int ee[maxn]; bool cmp(node a, node b){
return a.c > b.c;
} void init(){
memset(ff, false, sizeof(ff));
memset(ee, false, sizeof(ee));
for (int i = ; i < n; i++){
fa[i] = i;
}
} int find(int x){
if (x == fa[x])
return x;
else
return fa[x] = find(fa[x]);
} void Union(int x, int y, int z){
int a = find(x);
int b = find(y);
if (a == b){
if (ff[a])
return;
ans += z;
ff[a] = true;
}
else{
if (ff[a] && ff[b])
return;
ans += z;
fa[b] = a;
if (ff[a] || ff[b])
ff[a] = true;
}
} int main(){
while (~scanf("%d%d", &n, &m)){
if (n == && m == )
break;
init();
int u, v, c;
for (int i = ; i < m; i++){
scanf("%d%d%d", &u, &v, &c);
g[i].u = u;
g[i].v = v;
g[i].c = c;
}
//克鲁斯卡尔
sort(g, g + m, cmp); //按边从小到大排列
ans = ;
for (int i = ; i < m; i++){
Union(g[i].u, g[i].v, g[i].c);
}
printf("%lld\n", ans);
}
//system("pause");
return ;
}

hdu 3367 Pseudoforest 最大生成树★的更多相关文章

  1. hdu 3367 Pseudoforest(最大生成树)

    Pseudoforest Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  2. hdu 3367 Pseudoforest (最大生成树 最多存在一个环)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3367 Pseudoforest Time Limit: 10000/5000 MS (Java/Oth ...

  3. hdu 3367 Pseudoforest

    Pseudoforest Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  4. hdu 3367(与最大生成树无关。无关。无关。重要的事情说三遍+kruskal变形)

    Pseudoforest Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  5. HDU 3367 Pseudoforest(Kruskal)

    Pseudoforest Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  6. hdu 3367 Pseudoforest (最小生成树)

    Pseudoforest Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  7. hdu 3367 Pseudoforest(并查集)

    题意:有一种叫作Pseudoforest的结构,表示在无向图上,每一个块中选取至多包含一个环的边的集合,又称“伪森林”.问这个集合中的所有边权之和最大是多少? 分析:如果没有环,那么构造的就是最大生成 ...

  8. hdu 3367(Pseudoforest ) (最大生成树)

    Pseudoforest Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  9. HDU 3367 (伪森林,克鲁斯卡尔)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=3367 Pseudoforest Time Limit: 10000/5000 MS (Java/Oth ...

随机推荐

  1. Using Virtual Serial Ports on Linux (Ubuntu)

    http://www.xappsoftware.com/wordpress/2013/10/07/using-virtual-serial-ports-on-linux-ubuntu/?goback= ...

  2. POJ 2586 Y2K Accounting Bug(枚举大水题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  3. 超低功耗、无需网关,CSR智能家居蓝牙控制照明方案

    本文转载至 http://blog.csdn.net/justinjing0612/article/details/39250997 [导读] iOS 8 Beta2终于让智能家居HomeKit功能露 ...

  4. 闭包传参 余额计算 钩子hook 闭包中的this JavaScript 钩子

    闭包传参  余额计算    钩子hook 小程序 a=function(e){console.log(this)}() a=function(e){console.log(this)}() VM289 ...

  5. c3p0+spring

    1. 首先是jdbc.properties属性文件的编写,便于数据库移植: datasource.driverClassName=oracle.jdbc.driver.OracleDriverdata ...

  6. Git 和 SVN 之间的五个基本区别

    GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等.如果你是一个具有使用SVN背景的人,你需要做一定的思想转换,来适应GIT提供的一些概念和特征.所以,这篇文章的主要目的就是 ...

  7. IOS中调用系统拨打电话发送短信

    一.调用打电话界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat ...

  8. git format-patch 用法

    git format-patch HEAD^ # git format-patch -s 1bbe3c8c197a35f79bfddaba099270a2e54ea9c7 please replace ...

  9. UVA-10125(中途相遇法)

    题意: 给定一个整数集合,找出最大的d,使得a+b+c=d,a,b,c,d是集合中不同的元素; 思路: 如果单纯的枚举a,b,c的复杂度是O(n^3)的,为了降低复杂度,可以先把a+b的情形都找出来, ...

  10. Android 如何进入充电模式

    /************************************************************************* * Android 如何进入充电模式 * 说明: ...