problem

#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 ;
}

随机推荐

  1. HDU 2604 矩阵快速幂

    题目大意 给定长度为l的只有f,m两种字母 的序列,问不出现fff,fmf的序列个数有多少个 每次的下一个状态都与前一次状态的后两个字母有关 比如我令mm : 0 , mf : 1 , fm : 2 ...

  2. 实验吧-catalyst-system

    刚学逆向很多都不懂,本题也是在看了 http://countersite.org/articles/reverse_engineering/136-revers-s-alexctf-2017.html ...

  3. 互联网DSP广告系统架构及关键技术解析

    互联网DSP广告系统架构及关键技术解析 宿逆 关注 1.9 2017.10.09 17:05* 字数 8206 阅读 10271评论 2喜欢 60 广告和网络游戏是互联网企业主要的盈利模式 广告是广告 ...

  4. Hihocoder 1333 (splay)

    Problem 平衡树 splay2 题目大意 维护一个序列,支持四种操作: 操作1:添加一个数,编号为x,权值为y. 操作2:删除编号在区间[x,y]内的数. 操作3:将编号在区间[x,y]内的数的 ...

  5. ISO 7064:1983.MOD11-2校验码计算法 : (身份证校验码-18位)

    /* 假设某一17位数字是 17位数字 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 加权因子 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 计算17位 ...

  6. Mysql Innodb存储引擎 insert 死锁分析

    http://chenzhenianqing.cn/articles/1308.html

  7. ngTbale真分页实现排序、搜索等功能

    一. 真分页表格基础 1. 需求:分页,排序,搜索都是需要发API到服务端. 2. JS实现代码: getStorage是localStorage一个工具方法,可以自己写这个方法. API参数如下: ...

  8. 编译Linux使用的.a库文件

    编译Linux使用的.a库文件 首先是须要编译成.a的源文件 hello.h: #ifndef __INCLUDE_HELLO_H__ #define __INCLUDE_HELLO_H__ void ...

  9. 【CV论文阅读】YOLO:Unified, Real-Time Object Detection

    YOLO的一大特点就是快,在处理上可以达到完全的实时.原因在于它整个检测方法非常的简洁,使用回归的方法,直接在原图上进行目标检测与定位. 多任务检测: 网络把目标检测与定位统一到一个深度网络中,而且可 ...

  10. [miniApp] WeChat user login code

    in client/app.js, we put user login logic inside here, so that other module can reuse those code by ...