当前位置:网站首页>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;
}
边栏推荐
- According to the analysis of the Internet industry in 2022, how to choose a suitable position?
- AcWing 1142. 繁忙的都市 题解(最小生成树)
- Install Firefox browser on raspberry pie /arm device
- 修改px4飞控的系统时间
- WCF基金会
- LeetCode:1175. Prime permutation
- Set up [redis in centos7.x]
- 公钥\私人 ssh避password登陆
- 使用nodejs完成判断哪些项目打包+发版
- Send template message via wechat official account
猜你喜欢
对C语言数组的再认识
Instructions for using the domain analysis tool bloodhound
C language - array
黑马笔记---异常处理
How to manage distributed teams?
从底层结构开始学习FPGA----FIFO IP的定制与测试
一起看看matlab工具箱内部是如何实现BP神经网络的
Let's see how to realize BP neural network in Matlab toolbox
tansig和logsig的差异,为什么BP喜欢用tansig
AcWing 345. 牛站 题解(floyd的性质、倍增)
随机推荐
Js逆向——捅了【马蜂窝】的ob混淆与加速乐
Table table setting fillet
AcWing 1142. 繁忙的都市 题解(最小生成树)
Let's see how to realize BP neural network in Matlab toolbox
C语言实例_5
对C语言数组的再认识
Google released a security update to fix 0 days that have been used in chrome
Transplant DAC chip mcp4725 to nuc980
AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
WCF基金会
使用nodejs完成判断哪些项目打包+发版
免费白嫖的图床对比
AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
Typical problems of subnet division and super network construction
taro3.*中使用 dva 入门级别的哦
7.6 simulation summary
第三方跳转网站 出现 405 Method Not Allowed
How to evaluate load balancing performance parameters?
Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which