【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

显然最后会形成多个集合,每个集合里面的人能够可以互相到达。
则维护并查集的时候,顺便维护一下每个集合里面的最小值就好。
最后答案就为∑min{每个集合}

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
*/
#include <bits/stdc++.h>
using namespace std; const int N = 1e5; int f[N+10],mi[N+10],n,m;
bool bo[N+10]; int ff(int x){
if (f[x]==x) return x;
else return f[x] = ff(f[x]);
} int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= n;i++){
cin >> mi[i];
f[i] = i;
}
for (int i = 1;i <= m;i++){
int x,y;
cin >> x >> y;
int r1 = ff(x),r2 = ff(y);
if (r1!=r2){
f[r1] = r2;
mi[r2] = min(mi[r2],mi[r1]);
}
} long long ans = 0;
for (int i = 1;i <= n;i++){
int x = ff(i);
if (!bo[x]){
bo[x] = true;
ans += mi[x];
}
} cout << ans << endl; return 0;
}

最新文章

  1. CentOS 7 环境配置
  2. Lucene.net站内搜索—5、搜索引擎第一版实现
  3. 闭包和this
  4. PCI在linux系统中注册与注销示例
  5. 【Codeforces 723B】Text Document Analysis 模拟
  6. 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【七】——实现资源的分页
  7. CRM 权限与分派不一样问题
  8. Editplus从下载到使用
  9. poj 2406 Power Strings kmp算法
  10. 一步步写STM32 OS【二】环境搭建
  11. maven,本地仓库和私服nexus的配置,以及eclipse载入maven
  12. C#中用PadLeft、PadRight 补足位数
  13. ThinkPHP框架研究之一 基本函数 M和D的区别
  14. go-vim配置
  15. ubuntu 搭建svn服务器
  16. javac 小记
  17. findViewById中NullPointerException的错误
  18. I春秋——Misc(贝斯家族)
  19. [sh]getopt参数解析
  20. 解决jar包依赖:Spring IO platform推出bom

热门文章

  1. React开发实时聊天招聘工具 -第六章 登陆注册(1)
  2. JAVA基础数据类型
  3. HttpClient方式调用接口的java 简单案例源码+附jar包
  4. MongoDB + node-mongoskin简单演示样例
  5. 在JAVA中怎样跳出当前的多重嵌套循环?
  6. Codeforces 474D Flowers (线性dp 找规律)
  7. 搭建个人博客 方式2 使用jekyll
  8. SSM(spring,springMVC,Mybatis)框架的整合
  9. 50.Node.js 连接 MySQL
  10. AIX lsof 命令