当前位置:网站首页>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;
}
边栏推荐
- Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
- 分享一个通用的so动态库的编译方法
- 微信公众号发送模板消息
- 自旋与sleep的区别
- 让我们,从头到尾,通透网络I/O模型
- Yunna - work order management system and process, work order management specification
- DS-5/RVDS4.0变量初始化错误
- uva 1401 dp+Trie
- Supersocket 1.6 creates a simple socket server with message length in the header
- 405 method not allowed appears when the third party jumps to the website
猜你喜欢

力扣1037. 有效的回旋镖

Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform

一起看看matlab工具箱内部是如何实现BP神经网络的

从底层结构开始学习FPGA----FIFO IP的定制与测试

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

The MySQL database in Alibaba cloud was attacked, and finally the data was found

C language - array

Yunna | work order management measures, how to carry out work order management

Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which

Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
随机推荐
Force buckle 1037 Effective boomerang
今日问题-2022/7/4 lambda体中修改String引用类型变量
Neon Optimization: About Cross access and reverse cross access
Google发布安全更新,修复Chrome中已被利用的0 day
交叉验证如何防止过拟合
2022 Google CTF segfault Labyrinth WP
自旋与sleep的区别
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
JTAG debugging experience of arm bare board debugging
HMM notes
C语言实例_5
C语言实例_4
Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
微信公众号发送模板消息
从底层结构开始学习FPGA----FIFO IP的定制与测试
【C语言进阶篇】指针的8道笔试题
2022 Google CTF SEGFAULT LABYRINTH wp
Instructions for using the domain analysis tool bloodhound
让我们,从头到尾,通透网络I/O模型
Js逆向——捅了【马蜂窝】的ob混淆与加速乐