https://codeforces.com/contest/1095/problem/F

题解:并查集+最小生成树

TLE,WA,RE搞死中,就因为数组开小了,23333

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=410000;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q,v,u;
ll  a[N],w;
int pre[N];
struct node{int u,v;ll w;node(){};node(int _u,int _v,ll _w){u=_u;v=_v;w=_w;}bool operator <(const node&S)const{return w<S.w;}
}e[N];
int find(int x){int rt=x;while(pre[rt]!=rt){rt=pre[rt];}pre[x]=rt;//并查集路径压缩return rt;
}
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endifscanf("%d%d",&n,&m);int id=1;for(int i=1;i<=n;i++){pre[i]=i;scanf("%I64d",&a[i]);if(a[i]<=a[id])id=i;}int tot=0;for(int i=1;i<=n;i++){//if(i!=id)e[++tot]=node(i,id,a[i]+a[id]);}for(int i=1;i<=m;i++){scanf("%d%d%I64d",&u,&v,&w);e[++tot]=node(u,v,w);}sort(e+1,e+tot+1);ll ans=0;for(int i=1;i<=tot;i++){int x=find(e[i].u);int y=find(e[i].v);if(x!=y){pre[x]=pre[y];ans+=e[i].w;}}cout << ans << endl;//cout << "Hello world!" << endl;return 0;
}

Make It Connected相关推荐

  1. trogan连接不上_解决连接不上网(Connection not connected).doc

    解决连接不上网(Connection not connected).doc 解决连接不上网(Connection not connected) The computer doesn't connect ...

  2. HDU 4635 Strongly connected(缩点、最多可加边数使得仍然非强连通)

    整理的算法模板合集: ACM模板 HDU 4635 Strongly connected Give a simple directed graph with N nodes and M edges. ...

  3. 网络模型--Densely Connected Convolutional Networks

    Densely Connected Convolutional Networks CVPR2017 best paper Code: https://github.com/liuzhuang13/De ...

  4. (全网率先解决)Pycharm在Debug的时候出现frames are not available;Variable:Connected

    先说说我的情况,这样可以让你对号入座. 我是本地笔记本电脑使用Pycharm,但是Pycharm的Python解释器连接的是远程的实验室linux服务器.也就是说,你猜到了,我的是Pycharm专业版 ...

  5. 程序运行过程中遇到“ORA-03114: not connected to ORACLE”的问题解决

    程序运行过程中遇到"ORA-03114: not connected to ORACLE"的问题解决 参考文章: (1)程序运行过程中遇到"ORA-03114: not ...

  6. ORA-01940: cannot drop a user that is currently connected 问题解析

    xxx为待删除的用户名 SQL> drop user xxx cascade; 删除数据库用户的时候经常会遇到这样的错误: ORA-01940: cannot drop a user that ...

  7. 【CF913F】Strongly Connected Tournament 概率神题

    [CF913F]Strongly Connected Tournament 题意:有n个人进行如下锦标赛: 1.所有人都和所有其他的人进行一场比赛,其中标号为i的人打赢标号为j的人(i<j)的概 ...

  8. 论文阅读:DENSELY CONNECTED CONVOLUTIONAL NETWORKS

    概述 作者观察到目前的深度网络有一个重要的特点是shorted connected,认为能够训练极深的网络很可能就是由于这个原因. 于是作者提出了Densely connected convoluti ...

  9. 对Keil在线烧录程序弹出“The firmware of the connected J-Link[SN:xxxxxxxx] does not support......的问题解决

    问题:最近下载并使用Keil_v5.29,在线烧录程序时出现"The firmware of the connected J-Link[SN:xxxxxxxx] does not suppo ...

  10. 【Paper】2018_Nonlinear Consensus-Based Connected Vehicle Platoon Control Incorporating Car-Following

    [Y. Li, C. Tang, S. Peeta and Y. Wang, "Nonlinear Consensus-Based Connected Vehicle Platoon Con ...

最新文章

  1. 清华大学张悠慧:超越冯·诺依曼模型,实现软硬件去耦合的类脑计算(附视频)
  2. pmp考试必知的十个图和表
  3. 股市永不过时的黄金铁律:零下金叉疯狂买,零上死叉立即卖
  4. linux c 内存分配内存,Linuxc - 操作系统内存分配
  5. 稀疏大模型简述:从MoE、Sparse Attention到GLaM
  6. matlab knn,MATLAB K近邻算法 — knnsearch() 函数 | 学步园
  7. java 保留小数点后N位数(若干位),几种实现的方式总结
  8. 蓝桥杯 振兴中华——2013年省赛C/C++ A组真题3
  9. ServletRequest--从html页面获取信息
  10. 思科模拟器pnatlab,华为模拟器ensp桥接本地
  11. php设备巡检管理,设备巡检管理解决方案
  12. win 通过 Distro 安装 linux 子系统
  13. mysql 函数返回类型set_mysql自定义函数如何返回多个值
  14. Linux系统查看版本
  15. 输入小写字母转换acii和对应大写
  16. 【渝粤题库】陕西师范大学201771 中国古代文学(一) 作业
  17. 华晨宏盛分享2021年个人所得税起征点是个人所得税税率一览表
  18. 渗透测试之破解密码(3)
  19. 国家开放大学2021春1259西方行政学说题目
  20. Windows驱动_文件系统微小过滤驱动之三微小过滤驱动的操作

热门文章

  1. 在线考试计算机文化基础,计算机文化基础在线考试.pdf
  2. 对齐方式有那些_字节对齐不慎引发的挂死问题
  3. 4g ecgi 编码_4G学习之IMSI附着
  4. 最java大子矩阵和问题_最大子矩阵问题实例解析
  5. wifi 2.4g 5g 区别_wifi信号差,网速慢?可能是你没有配置好2.4G和5G WiFi
  6. python项目策划书_跟着销售学python系列(1)--实践项目骨架(1)
  7. titanic数据集_TF2.0结构化数据建模流程范例
  8. JavaScript中的三种常用继承方法
  9. arcgis悬挂点修改_ArcGis拓扑的那些事儿(拓扑应用过程三)
  10. api可以主动采集用户数据吗_现在的前端框架全是通过API获得数据,如何记录用户登录状态?...