当前位置:网站首页>AcWing 1142. Busy urban problem solving (minimum spanning tree)
AcWing 1142. Busy urban problem solving (minimum spanning tree)
2022-07-07 01:36:00 【Mr. Qiao Da】
AcWing 1142. A busy city
Kruskal algorithm finds the largest edge in the minimum spanning tree , Record the last edge added to the minimum spanning tree
#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;
}
边栏推荐
- [advanced C language] 8 written questions of pointer
- Comparison of picture beds of free white whoring
- Transformation transformation operator
- swiper组件中使用video导致全屏错位
- Neon Optimization: an optimization case of log10 function
- Js逆向——捅了【马蜂窝】的ob混淆与加速乐
- Let's see how to realize BP neural network in Matlab toolbox
- Spark TPCDS Data Gen
- [chip scheme design] pulse oximeter
- What does front-end processor mean? What is the main function? What is the difference with fortress machine?
猜你喜欢
![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]

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

Right mouse button customization
![[signal and system]](/img/aa/a65d6da1d1d9410254ca7b775e24a6.png)
[signal and system]

Gazebo的安装&与ROS的连接

新工作感悟~辞旧迎新~

C language - array

【信号与系统】

Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP

Send template message via wechat official account
随机推荐
Dark horse notes - exception handling
Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
Transplant DAC chip mcp4725 to nuc980
Gazebo的安装&与ROS的连接
Share a general compilation method of so dynamic library
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
2022 Google CTF SEGFAULT LABYRINTH wp
Google released a security update to fix 0 days that have been used in chrome
Wood extraction in Halcon
dvajs的基础介绍及使用
Yunna | work order management measures, how to carry out work order management
新工作感悟~辞旧迎新~
长按按钮执行函数
鼠标右键 自定义
THREE. AxesHelper is not a constructor
Today's question -2022/7/4 modify string reference type variables in lambda body
2022 Google CTF SEGFAULT LABYRINTH wp
各种语言,软件,系统的国内镜像,收藏这一个仓库就够了: Thanks-Mirror
拖拽改变顺序
7.6 simulation summary