当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Typical problems of subnet division and super network construction

MySQL script batch queries all tables containing specified field types in the database

2022 Google CTF segfault Labyrinth WP

Make Jar, Not War

Force buckle 1037 Effective boomerang

微信公众号发送模板消息

Analysis of mutex principle in golang

ClickHouse字段分组聚合、按照任意时间段粒度查询SQL

一起看看matlab工具箱内部是如何实现BP神经网络的
![[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)](/img/40/dc45df3cd3ee7642277eff899bc6aa.png)
[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)
随机推荐
编译命令行终端 swift
NEON优化:关于交叉存取与反向交叉存取
HMM 笔记
C语言实例_3
Send template message via wechat official account
1123. The nearest common ancestor of the deepest leaf node
Dark horse notes - create immutable sets and streams
AI automatically generates annotation documents from code
移植DAC芯片MCP4725驱动到NUC980
LeetCode:1175. 质数排列
公钥\私人 ssh避password登陆
POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
Lldp compatible CDP function configuration
云呐|工单管理办法,如何开展工单管理
How to prevent overfitting in cross validation
THREE. AxesHelper is not a constructor
Taro2.* applet configuration sharing wechat circle of friends
Neon Optimization: About Cross access and reverse cross access
Make Jar, Not War
golang中的atomic,以及CAS操作