当前位置:网站首页>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;
}
边栏推荐
- Long press the button to execute the function
- WCF基金会
- Instructions for using the domain analysis tool bloodhound
- Spark TPCDS Data Gen
- HMM notes
- AI 从代码中自动生成注释文档
- go-zero微服务实战系列(九、极致优化秒杀性能)
- The difference between Tansig and logsig. Why does BP like to use Tansig
- AcWing 346. Solution to the problem of water splashing festival in the corridor (deduction formula, minimum spanning tree)
- 使用nodejs完成判断哪些项目打包+发版
猜你喜欢

Gin introduction practice

Yunna - work order management system and process, work order management specification

子网划分、构造超网 典型题

1123. The nearest common ancestor of the deepest leaf node

tansig和logsig的差异,为什么BP喜欢用tansig

第三方跳转网站 出现 405 Method Not Allowed

免费白嫖的图床对比

从底层结构开始学习FPGA----FIFO IP的定制与测试

Let's see how to realize BP neural network in Matlab toolbox

LeetCode:1175. Prime permutation
随机推荐
数据手册中的词汇
移植DAC芯片MCP4725驱动到NUC980
拖拽改变顺序
POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
How to evaluate load balancing performance parameters?
Taro2.* applet configuration sharing wechat circle of friends
AcWing 345. 牛站 题解(floyd的性质、倍增)
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
C language - array
Transplant DAC chip mcp4725 to nuc980
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
公钥\私人 ssh避password登陆
如何管理分布式团队?
Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
Set up [redis in centos7.x]
Neon Optimization: an instruction optimization case of matrix transpose
AI automatically generates annotation documents from code
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
Metauniverse urban legend 02: metaphor of the number one player
[JS] obtain the N days before and after the current time or the n months before and after the current time (hour, minute, second, year, month, day)