当前位置:网站首页>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;
}
边栏推荐
- Force buckle 1037 Effective boomerang
- 2022 Google CTF segfault Labyrinth WP
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
- Neon Optimization: summary of performance optimization experience
- Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
- 编译命令行终端 swift
- Boot - Prometheus push gateway use
- LeetCode:1175. 质数排列
- 免费白嫖的图床对比
- Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
猜你喜欢
![[advanced C language] 8 written questions of pointer](/img/d4/c9bb2c8c9fd8f54a36e463e3eb2fe0.png)
[advanced C language] 8 written questions of pointer

JTAG debugging experience of arm bare board debugging

Let's see through the network i/o model from beginning to end

Comparison of picture beds of free white whoring

Transplant DAC chip mcp4725 to nuc980

Lldp compatible CDP function configuration
![JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]](/img/40/da56fe6468da64dd37d6b5b0082206.png)
JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]

2022 Google CTF SEGFAULT LABYRINTH wp

Dark horse notes - exception handling

405 method not allowed appears when the third party jumps to the website
随机推荐
DS-5/RVDS4.0变量初始化错误
How to evaluate load balancing performance parameters?
[case sharing] basic function configuration of network loop detection
curl 命令
ClickHouse字段分组聚合、按照任意时间段粒度查询SQL
Body mass index program, entry to write dead applet project
今日问题-2022/7/4 lambda体中修改String引用类型变量
Make Jar, Not War
HMM 笔记
golang中的atomic,以及CAS操作
负载均衡性能参数如何测评?
Google发布安全更新,修复Chrome中已被利用的0 day
[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)
NEON优化:性能优化常见问题QA
Installation and testing of pyflink
golang中的Mutex原理解析
分享一个通用的so动态库的编译方法
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
LeetCode:1175. 质数排列
2022 Google CTF SEGFAULT LABYRINTH wp