当前位置:网站首页>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;
}
边栏推荐
- Neon Optimization: an optimization case of log10 function
- Share a general compilation method of so dynamic library
- AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
- AcWing 1142. 繁忙的都市 题解(最小生成树)
- AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
- Yunna | work order management software, work order management software app
- AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
- 修改px4飞控的系统时间
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
- LeetCode:1175. Prime permutation
猜你喜欢
Make Jar, Not War
Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
[signal and system]
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Dark horse notes - create immutable sets and streams
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
【C语言进阶篇】指针的8道笔试题
AI 从代码中自动生成注释文档
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Set WordPress pseudo static connection (no pagoda)
随机推荐
How to evaluate load balancing performance parameters?
剑指 Offer II 035. 最小时间差-快速排序加数据转换
Spark TPCDS Data Gen
Vocabulary in Data Book
Typical problems of subnet division and super network construction
字节P7专业级讲解:接口测试常用工具及测试方法,福利文
swiper组件中使用video导致全屏错位
C language - array
Neon Optimization: summary of performance optimization experience
454-百度面经1
AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
Comparison of picture beds of free white whoring
Appium基础 — Appium Inspector定位工具(一)
Neon Optimization: About Cross access and reverse cross access
1123. 最深叶节点的最近公共祖先
交叉验证如何防止过拟合
Send template message via wechat official account
C语言实例_3
[advanced C language] 8 written questions of pointer
AI automatically generates annotation documents from code