当前位置:网站首页>AcWing 1142. 繁忙的都市 题解(最小生成树)
AcWing 1142. 繁忙的都市 题解(最小生成树)
2022-07-06 18:00:00 【乔大先生】
AcWing 1142. 繁忙的都市
克鲁斯卡尔算法求最小生成树里最大的边,记录最后加入最小生成树内的边即可
#include<bits/stdc++.h>
using namespace std;
const int N = 8010;
struct Edge{
int a, b, w;
bool operator < (const Edge &t) const{
return w < t.w;
}
}e[N];
int p[N];
int n, m;
int find(int x){
if(x != p[x]) p[x] = find(p[x]);
return p[x];
}
int main()
{
cin>>n>>m;
for(int i = 1; i <= n; i ++ ) p[i] = i;
for(int i = 0; i < m; i ++ ){
int a, b, c;
cin>>a>>b>>c;
e[i] = {
a, b, c};
}
sort(e, e + m);
int res = 0;
for(int i = 0; i < m; i ++ ){
int a = find(e[i].a), b = find(e[i].b), w = e[i].w;
if(a != b){
p[a] = b;
res = w;
}
}
cout<<n - 1<<' '<<res<<endl;
return 0;
}
边栏推荐
- HMM notes
- Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
- C language - array
- 剑指 Offer II 035. 最小时间差-快速排序加数据转换
- Taro applet enables wxml code compression
- Vocabulary in Data Book
- JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]
- 黑马笔记---创建不可变集合与Stream流
- ClickHouse字段分组聚合、按照任意时间段粒度查询SQL
- How to evaluate load balancing performance parameters?
猜你喜欢

如何管理分布式团队?

云呐|工单管理软件,工单管理软件APP

shell脚本快速统计项目代码行数

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

LeetCode:1175. Prime permutation

一起看看matlab工具箱内部是如何实现BP神经网络的
![[case sharing] basic function configuration of network loop detection](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[case sharing] basic function configuration of network loop detection

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

C language - array

从底层结构开始学习FPGA----FIFO IP的定制与测试
随机推荐
Implementation principle of waitgroup in golang
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
ClickHouse字段分组聚合、按照任意时间段粒度查询SQL
黑马笔记---创建不可变集合与Stream流
各种语言,软件,系统的国内镜像,收藏这一个仓库就够了: Thanks-Mirror
系统休眠文件可以删除吗 系统休眠文件怎么删除
JTAG debugging experience of arm bare board debugging
taro3.*中使用 dva 入门级别的哦
Oracle: Practice of CDB restricting PDB resources
How to prevent overfitting in cross validation
从底层结构开始学习FPGA----FIFO IP的定制与测试
Installation of gazebo & connection with ROS
Amway wave C2 tools
Share a general compilation method of so dynamic library
THREE. AxesHelper is not a constructor
接收用户输入,身高BMI体重指数检测小业务入门案例
Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
shell脚本快速统计项目代码行数
NEON优化:矩阵转置的指令优化案例
免费白嫖的图床对比