当前位置:网站首页>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;
}
边栏推荐
- 图片打水印 缩放 和一个输入流的转换
- According to the analysis of the Internet industry in 2022, how to choose a suitable position?
- 7.6模拟赛总结
- 云呐-工单管理制度及流程,工单管理规范
- Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
- WCF基金会
- Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
- Yunna | work order management measures, how to carry out work order management
- How to manage distributed teams?
- Set up [redis in centos7.x]
猜你喜欢

dvajs的基础介绍及使用

Yunna | work order management software, work order management software app

今日问题-2022/7/4 lambda体中修改String引用类型变量

Gazebo的安装&与ROS的连接

Installation of gazebo & connection with ROS

免费白嫖的图床对比

AI automatically generates annotation documents from code

According to the analysis of the Internet industry in 2022, how to choose a suitable position?

2022 Google CTF segfault Labyrinth WP

2022 Google CTF SEGFAULT LABYRINTH wp
随机推荐
剑指 Offer II 035. 最小时间差-快速排序加数据转换
C语言实例_3
Appium基础 — Appium Inspector定位工具(一)
子网划分、构造超网 典型题
ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
Taro applet enables wxml code compression
Taro2.* applet configuration sharing wechat circle of friends
hdu 4661 Message Passing(木DP&amp;组合数学)
Today's question -2022/7/4 modify string reference type variables in lambda body
今日问题-2022/7/4 lambda体中修改String引用类型变量
拖拽改变顺序
分享一个通用的so动态库的编译方法
C语言实例_2
JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]
Neon Optimization: an instruction optimization case of matrix transpose
[advanced C language] 8 written questions of pointer
字节P7专业级讲解:接口测试常用工具及测试方法,福利文
C language instance_ four
Google发布安全更新,修复Chrome中已被利用的0 day
Yunna | work order management measures, how to carry out work order management