当前位置:网站首页>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;
}
边栏推荐
- Amway wave C2 tools
- Gazebo的安装&与ROS的连接
- C语言实例_2
- Install Firefox browser on raspberry pie /arm device
- [case sharing] basic function configuration of network loop detection
- Taro 小程序开启wxml代码压缩
- 安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
- Js逆向——捅了【马蜂窝】的ob混淆与加速乐
- Oracle: Practice of CDB restricting PDB resources
- [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)
猜你喜欢
黑马笔记---异常处理
Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]
[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)
According to the analysis of the Internet industry in 2022, how to choose a suitable position?
HMM notes
Yunna | work order management software, work order management software app
How to manage distributed teams?
1123. 最深叶节点的最近公共祖先
Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
随机推荐
Atomic in golang, and cas Operations
LeetCode:1175. 质数排列
The cost of returning tables in MySQL
接收用户输入,身高BMI体重指数检测小业务入门案例
HMM 笔记
Atomic in golang and CAS operations
[chip scheme design] pulse oximeter
让我们,从头到尾,通透网络I/O模型
uva 1401 dp+Trie
Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
The difference between spin and sleep
Neon Optimization: performance optimization FAQ QA
json学习初体验–第三者jar包实现bean、List、map创json格式
Let's see through the network i/o model from beginning to end
对C语言数组的再认识
[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)
LeetCode:1175. Prime permutation
负载均衡性能参数如何测评?
AI automatically generates annotation documents from code
golang中的Mutex原理解析