$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 ;
}
随机推荐
- 爬虫之Re库
一.常见匹配模式 \W # 匹配字母数字及下划线 \W # 匹配非字母数字下划线 \s # 匹配任意空白字符,等价于[\t\n\r\f] \S # 匹配任意非空字符 \d # 匹配任意数字,等价于[0 ...
- Linux学习笔记(二) 文件管理
了解 Linux 系统基本的文件管理命令可以帮助我们更好的使用 Linux 系统,以下介绍几个常用的文件管理命令 1.pwd pwd 是 Print Working Directory 的简写,用于显 ...
- java 十三周总结
- LINUX-RPM 包 - (Fedora, Redhat及类似系统)
rpm -ivh package.rpm 安装一个rpm包 rpm -ivh --nodeeps package.rpm 安装一个rpm包而忽略依赖关系警告 rpm -U package.rpm 更新 ...
- Python 开发面试题
Python部分 将一个字符串逆序,不能使用反转函数 求从10到100中能被3或5整除的数的和 What is Python? What are the benefits of using Pytho ...
- [POJ3162]Walking Race(DP + 单调队列)
传送门 题意:一棵n个节点的树.wc爱跑步,跑n天,第i天从第i个节点开始跑步,每次跑到距第i个节点最远的那个节点(产生了n个距离),现在要在这n个距离里取连续的若干天,使得这些天里最大距离和最小距离 ...
- noip模拟赛 猜数字
题目描述 LYK在玩猜数字游戏. 总共有n个互不相同的正整数,LYK每次猜一段区间的最小值.形如[li,ri]这段区间的数字的最小值一定等于xi. 我们总能构造出一种方案使得LYK满意.直到…… LY ...
- Ubuntu 16.04下Markdown编辑器Haroopad
1.下载deb包 地址:https://bitbucket.org/rhiokim/haroopad-download/downloads/haroopad-v0.13.2-x64.deb 这里是历史 ...
- Pivotal-tc-Server与Tomcat区别
Pivotal-tc-Server之前叫做SpringSource tc Server,包含三个版本分别是:Spring版.标准版和开发版,但其中只有开发版是免费的.比如在STS中包含的版本就是开发板 ...
- BP神经网络及其在教学质量评价中 的应用
本文学习笔记是自己的理解,如有错误的地方,请大家指正批评.共同进步.谢谢! 之前的教学质量评价,仅仅是通过对教学指标的简单处理.如求平均值或人为的给出各指标的权值来加权求和,其评价结果带有非常大主观性 ...