http://acm.timus.ru/problem.aspx?space=1&num=1982

题解:最小生成树

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int M=100000+10;
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,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
int pre[N],a[N];
char str;
struct node{int u,v,w;bool operator<(const node&S)const{return w<S.w;}
}e[N];
int find(int x){return pre[x]==x?x:pre[x]=find(pre[x]);}
bool marge(int u,int v){int tu=find(u);int tv=find(v);if(tu!=tv){pre[tu]=tv;return 1;}return 0;
}
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d%d",&n,&k);for(int i=1;i<=n;i++){pre[i]=i;}for(int i=1;i<=k;i++){scanf("%d",&a[i]);if(i!=1)marge(a[i-1],a[i]);}for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){scanf("%d",&m);if(i<=j)continue;e[++cnt].u=i;e[cnt].v=j;e[cnt].w=m;}}sort(e+1,e+cnt+1);for(int i=1;i<=cnt;i++){if(marge(e[i].u,e[i].v)){ans+=e[i].w;}}cout<<ans<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}

Electrification Plan相关推荐

  1. URAL-1982 Electrification Plan 最小生成树

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1982 题意:无向图,给n个点,n^2条边,每条边有个一权值,其中有k个点有发电站,给出这 ...

  2. URAL 1982. Electrification Plan(并查集)

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1982 Some country has n cities. The government ...

  3. linux中600是什么权限,linux系统中文件的权限

    查看文件权限的语句: 在终端输入: ls -l xxx.xxx (xxx.xxx是文件名) 那么就会出现相类似的信息,主要都是这些: -rw-rw-r-- 一共有10位数 其中: 最前面那个 - 代表 ...

  4. Maven 的Could not calculate build plan错误解决方法(不一定适用,看原因)

    Maven 的Could not calculate build plan错误解决方法(不一定适用,看原因): 1.将C:\Users\a\.m2\repository\org\apache\mave ...

  5. 《Microsoft Sql server 2008 Internals》读书笔记--第九章Plan Caching and Recompilation(10)

    <Microsoft Sql server 2008 Internals>读书笔记订阅地址: http://www.cnblogs.com/downmoon/category/230397 ...

  6. 鸿蒙霸榜GitHub,从最初的Plan B到“取代Android”?

    整理 | 郭芮 出品 | CSDN(ID:CSDNnews) 距离 8 月 9 日鸿蒙(HarmonyOS)正式发布刚刚过去九天,这场由华为领衔的技术风暴,经过十年蛰伏,终于成功引爆全球.与此同时,一 ...

  7. 影像组学视频学习笔记(43)-标准差、标准误及95%置信区间CI、Li‘s have a solution and plan.

    作者:北欧森林 链接:https://www.jianshu.com/p/f09d0f97592f 来源:简书,已获授权转载 本笔记来源于B站Up主: 有Li 的影像组学系列教学视频 本节(43)主要 ...

  8. 影像组学视频学习笔记(42)-影像组学特征提取问题解决过程复现、Li‘s have a solution and plan.

    作者:北欧森林 链接:https://www.jianshu.com/p/c3e6de2f79b3 来源:简书,已获转载授权 本笔记来源于B站Up主: 有Li 的影像组学系列教学视频 本节(42)主要 ...

  9. 影像组学视频学习笔记(41)-如何使用软件提取组学特征、Li‘s have a solution and plan.

    作者:北欧森林 链接:https://www.jianshu.com/p/72186eb3e395 来源:简书,已获授权转载 本笔记来源于B站Up主: 有Li 的影像组学系列教学视频 本节(41)主要 ...

最新文章

  1. linux下使profile和.bash_profile立即生效的方法
  2. oracle ORA-00604和BadImageFormatException的解决方法
  3. printf输出颜色和ANSI控制码(高亮,下划线,闪烁,光标位置,清屏等)
  4. STM32 之九 HAL 库串口(USART/UART)驱动 BUG 及解决方法
  5. MySQL查询条件中的各种运算符/操作符说明
  6. Cron表达式、定时任务
  7. scikit-learn——快速入门 - daniel-D(转)
  8. 【华为云技术分享】实战笔记丨JDBC问题定位指南
  9. leetcode 题解 java_leetcode-java题解(每天更新)
  10. java中PrepareStatement使用的一点小问题
  11. CVPR 2020评审结果放出,魏秀参博士教你如何rebuttal!!!
  12. 自动交易软件的功能特点能满足哪些要求?
  13. js获取传统节假日_js判断节假日实例代码
  14. 信用修复的社会意义及基本概念、要素?
  15. CS,四,组网及因特网
  16. 英语中并列句的四种类型
  17. 2.《THE WISDOM OF LIFE》_叔本华
  18. 当你的职业是一名IT项目经理
  19. 离线强化学习(Offline RL)系列3: (算法篇) AWAC算法详解与实现
  20. python基础5-模块定义、导入方法、import本质、time和datetime、random、os、sys、shutil、shelve、xml、ConfigParser、hashlib、re

热门文章

  1. java扫描包内所有类_第20天|Java入门有野,修饰符
  2. html页脚行距,html Word行距怎么设置
  3. java+synchro_synchrozied,wait()与notify()的理解
  4. linux 加密我的主目录,NFS与加密的ubuntu主目录
  5. mysql 查询排行_通过mysql查询排行榜
  6. java中注解的解析_【Java】中的注解与注解解析器
  7. findbugs插件_提升编码效率的IntelliJ IDEA必备插件
  8. 三十五、Scrapy 中的杂知识总结和代理池的编写
  9. 计算机网络应用基础第一章试题,计算机网络应用基础第一章测试题
  10. 知识图谱领域有哪些最新研究进展?不妨从EMNLP 2021录用论文寻找答案