$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 安装 phpstorm 并破解
下载官方软件linux版phpstrom, 貌似很卡要FQ. 我下载我的百度网盘备用了.解压目录, mv 到/opt/ 下 cd进 bin目录下chmod 777 phpstorm.sh执行 ./ ...
- python3支持excel读写
1.安装setuptools-17.0.tar.gz cmd 进入命令行 cd C:\Users\vivi\Desktop\pythonforexcel\setuptools-17.0\setupto ...
- js中匿名函数的N种写法
匿名函数没有实际名字,也没有指针,怎么执行? 关于匿名函数写法,很发散~ +号是让函数声明转换为函数表达式.汇总一下 最常见的用法: 代码如下: (function() { alert('water ...
- HBase的集群搭建
前提:已经安装过jdk,HDFS集群和zookeeper,我的集群规划见HDFS的文章中 1.在1上安装配置hbase 下载:http://mirror.bit.edu.cn/apache/hbase ...
- Oracle 11.2.0.4.0安装
http://opensgalaxy.com/2015/08/25/oracle11-2-0-4-0%E5%AE%89%E8%A3%85%E5%8F%8A%E8%A1%A5%E4%B8%81%E8%8 ...
- POJ 1328 Radar Installation 贪心算法
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- [bzoj 1047][HAOI2007]理想正方形(单调队列)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1047 分析: 第一感觉二维线段树当然没问题但是挺慢的. 注意到要求的正方形形中的最大最小边长是 ...
- 定义Portal显示规则
Defining Portal Display Rules Use You use the Portal Display Rules editor to create and edit rule co ...
- Spring Boot在开发时实现热部署(开发时修改文件保存后自动重启应用)(spring-boot-devtools)
热部署是什么 大家都知道在项目开发过程中,常常会改动页面数据或者修改数据结构,为了显示改动效果,往往需要重启应用查看改变效果,其实就是重新编译生成了新的Class文件,这个文件里记录着和代码等对应的各 ...
- Spring MVC使用@RestController生成JSON示例
继上一章的生成JSON示例http://www.cnblogs.com/EasonJim/p/7500405.html,现在还有另一种选择,就是使用@RestController,下面将参照上一节例子 ...