$P2126 Mzc家中的男家丁$
#ifdef Dubug
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
inline LL In() { LL res(0),f(1); register char c ;
while(isspace(c=getchar())) ; c == '-'? f = -1 , c = getchar() : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(c=getchar())) ;
return res * f ;
}
int n , m ;
const int N = 2300 + 5 ;
const int M = 400000 + 5 ;
struct node {
int u ;
int v ;
int w ;
};
node edge[M] ;
int fa[N] ;
int ans = 0 ;
bool cmp(node x,node y) {
return x.w < y.w ;
}
inline int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]) ;
}
inline void kruskal() {
sort(edge+1,edge+m+1,cmp) ;
for(register int i=1;i<=m;i++){
int x = find(edge[i].u) , y = find(edge[i].v) ;
if(x == y) continue ;
fa[x] = y , ans += edge[i].w ;
}
}
signed main() {
n = In() ; m = In() ;
for(register int i=1;i<=n;i++) fa[i] = i ;
for(register int i=1;i<=m;i++) {
int u = In() , v = In() , w = In() ;
edge[i] = node{u,v,w} ;
}
kruskal() ;
cout << ans << endl ;
return 0 ;
}
随机推荐
- LINUX-字符设置和文件格式转换
dos2unix filedos.txt fileunix.txt 将一个文本文件的格式从MSDOS转换成UNIX unix2dos fileunix.txt filedos.txt 将一个文本文件的 ...
- 【Codeforces 1019A】Elections
[链接] 我是链接,点我呀:) [题意] 每个人都有自己喜欢的队员 但是如果贿赂他们可以让他们更改自己喜欢的队员 问你最少要花多少钱贿赂队员才能让1号队员严格有最多的人喜欢? [题解] 除了1号之外, ...
- 兼容IE8 addEventListener、removeEventListener 函数
//兼容bind函数 if(!Function.prototype.bind){ Function.prototype.bind = function(){ if(typeof this !== 'f ...
- Prime Land(poj 1365)
题意:这题题意难懂,看了题解才知道的.比如第二组sample,就是5^1*2^1=10, 求10-1即9的质因数分解,从大到小输出,即3^2.本来很简单的嘿,直接最快速幂+暴力最裸的就行了. #inc ...
- [NOIP2004]FBI树
题目描述 我们可以把由“0”和“1”组成的字符串分为三类:全“0”串称为B串,全“1”串称为I串,既含“0”又含“1”的串则称为F串. FBI树是一种二叉树,它的结点类型也包括F结点,B结点和I结点三 ...
- Spring-data-jpa 笔记(二) Repository 详解
基础的 Repository 提供了最基本的数据访问功能,其几个子接口则扩展了一些功能.它们的继承关系如下: Repository: 是 spring Data 的一个核心接口,它不提供任何方法,开发 ...
- pojo类对应的就是数据库中的表,pojo类属性类型一定要用包装类Integer等
pojo类对应的就是数据库中的表,pojo类属性类型一定要用包装类Integer等 pojo类对应的就是数据库中的表,pojo类属性类型一定要用包装类Integer等 pojo类对应的就是数据库中的表 ...
- Bitmap工具类BitmapHelper
BitmapHelper 提供一些获取本地缩略图,获取网络图片.dp与px的相互转换等方法. import java.io.ByteArrayInputStream; import java.io.B ...
- javascript 将中文符号转换成英文符号
javascript 将中文符号转换成英文符号 CreateTime--2018年3月30日09:01:29 Author:Marydon /** * 将中文符号转换成英文符号 */ functi ...
- C++学习之extern "C"
我们知道,extern关键字可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义.这里起到的是声明作用范围的用处.另外,extern还可以与 ...