当前位置:网站首页>AcWing 1140. 最短网络 (最小生成树)
AcWing 1140. 最短网络 (最小生成树)
2022-07-06 18:00:00 【乔大先生】
AcWing 1140. 最短网络
最小生成树模板
#include<bits/stdc++.h>
using namespace std;
const int N = 210;
int dist[N]; //dist记录的是这个点距离连通块的距离
int n, m;
int w[N][N];
bool st[N];
int prime(){
int res = 0;
memset(dist, 0x3f, sizeof dist);
dist[1] = 0; //初始化连通块内只有编号为1的点
for(int i = 1; i <= n; i ++ ){
int t = -1;
for(int j = 1; j <= n; j ++ ){
if(!st[j] && (t == -1 || dist[t] > dist[j])){
t = j;
}
}
res += dist[t];
st[t] = true;
for(int j = 1; j <= n; j ++ ){
dist[j] = min(dist[j], w[t][j]); //dist记录的是这个点距离连通块的距离,此时t是连通块内最靠外的点
}
}
return res;
}
int main()
{
cin>>n;
for(int i = 1; i <= n; i ++ ){
for(int j = 1; j <= n; j ++ ){
cin>>w[i][j];
}
}
cout<<prime()<<endl;
return 0;
}
边栏推荐
猜你喜欢
2022 Google CTF segfault Labyrinth WP
Yunna | work order management software, work order management software app
[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)
修改px4飞控的系统时间
Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
Instructions for using the domain analysis tool bloodhound
Dark horse notes - create immutable sets and streams
JTAG debugging experience of arm bare board debugging
系统休眠文件可以删除吗 系统休眠文件怎么删除
[advanced C language] 8 written questions of pointer
随机推荐
NEON优化:关于交叉存取与反向交叉存取
数据手册中的词汇
Receive user input, height BMI, BMI detection small business entry case
Force buckle 1037 Effective boomerang
云呐|工单管理软件,工单管理软件APP
Body mass index program, entry to write dead applet project
THREE.AxesHelper is not a constructor
分享一个通用的so动态库的编译方法
C # method of calculating lunar calendar date 2022
字节P7专业级讲解:接口测试常用工具及测试方法,福利文
微信公众号发送模板消息
Dark horse notes - create immutable sets and streams
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Lldp compatible CDP function configuration
7.6 simulation summary
交叉验证如何防止过拟合
Make Jar, Not War
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
HMM 笔记
编译命令行终端 swift