当前位置:网站首页>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;
}
边栏推荐
- What does security capability mean? What are the protection capabilities of different levels of ISO?
- 454-百度面经1
- 免费白嫖的图床对比
- Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
- AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
- Gazebo的安装&与ROS的连接
- golang 基础 —— 数据类型
- DS-5/RVDS4.0变量初始化错误
- Yunna - work order management system and process, work order management specification
- 域分析工具BloodHound的使用说明
猜你喜欢

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

AcWing 345. 牛站 题解(floyd的性质、倍增)

Today's question -2022/7/4 modify string reference type variables in lambda body

The difference between Tansig and logsig. Why does BP like to use Tansig

How to manage distributed teams?

盒子拉伸拉扯(左右模式)

According to the analysis of the Internet industry in 2022, how to choose a suitable position?

2022 Google CTF segfault Labyrinth WP

Appium自动化测试基础 — uiautomatorviewer定位工具

2022 Google CTF SEGFAULT LABYRINTH wp
随机推荐
[advanced C language] 8 written questions of pointer
Set WordPress pseudo static connection (no pagoda)
Gin 入门实战
数据手册中的词汇
Right mouse button customization
【C语言进阶篇】指针的8道笔试题
grep查找进程时,忽略grep进程本身
docker 方法安装mysql
How to manage distributed teams?
Spark TPCDS Data Gen
搭建【Redis in CentOS7.x】
736. Lisp 语法解析 : DFS 模拟题
Add the applet "lazycodeloading": "requiredcomponents" in taro,
安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
The difference between Tansig and logsig. Why does BP like to use Tansig
C language - array
AI 从代码中自动生成注释文档
AcWing 345. 牛站 题解(floyd的性质、倍增)
Transformation transformation operator
鼠标右键 自定义