当前位置:网站首页>AcWing 1140. Shortest network (minimum spanning tree)
AcWing 1140. Shortest network (minimum spanning tree)
2022-07-07 01:36:00 【Mr. Qiao Da】
AcWing 1140. The shortest network
Minimum spanning tree template
#include<bits/stdc++.h>
using namespace std;
const int N = 210;
int dist[N]; //dist It records the distance between this point and the connected block
int n, m;
int w[N][N];
bool st[N];
int prime(){
int res = 0;
memset(dist, 0x3f, sizeof dist);
dist[1] = 0; // Only the number in the initialized connected block is 1 The point of
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 It records the distance between this point and the connected block , here t Is the outermost point in the connected block
}
}
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;
}
边栏推荐
- AcWing 1140. 最短网络 (最小生成树)
- Install Firefox browser on raspberry pie /arm device
- golang 基础 —— 数据类型
- Taro applet enables wxml code compression
- C language instance_ three
- AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
- Appium基础 — Appium Inspector定位工具(一)
- 移植DAC芯片MCP4725驱动到NUC980
- Receive user input, height BMI, BMI detection small business entry case
- c语言—数组
猜你喜欢
Gazebo的安装&与ROS的连接
Js逆向——捅了【马蜂窝】的ob混淆与加速乐
LeetCode:1175. 质数排列
修改px4飞控的系统时间
云呐|工单管理办法,如何开展工单管理
LeetCode. 剑指offer 62. 圆圈中最后剩下的数
Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
Can the system hibernation file be deleted? How to delete the system hibernation file
子网划分、构造超网 典型题
Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
随机推荐
How to prevent overfitting in cross validation
AcWing 1140. 最短网络 (最小生成树)
Neon Optimization: an instruction optimization case of matrix transpose
curl 命令
Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
数据手册中的词汇
云呐-工单管理制度及流程,工单管理规范
Spark TPCDS Data Gen
分享一个通用的so动态库的编译方法
云呐|工单管理办法,如何开展工单管理
swiper组件中使用video导致全屏错位
Installation of gazebo & connection with ROS
Send template message via wechat official account
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Dark horse notes - create immutable sets and streams
增加 pdf 标题浮窗
云呐|工单管理软件,工单管理软件APP
2022 Google CTF SEGFAULT LABYRINTH wp
AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
WCF基金会