当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Wood extraction in Halcon

LeetCode. 剑指offer 62. 圆圈中最后剩下的数

Gin 入门实战

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

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

Body mass index program, entry to write dead applet project

Comparison of picture beds of free white whoring

域分析工具BloodHound的使用说明

mongodb查看表是否导入成功

对C语言数组的再认识
随机推荐
2022 Google CTF SEGFAULT LABYRINTH wp
如何管理分布式团队?
Yunna - work order management system and process, work order management specification
使用nodejs完成判断哪些项目打包+发版
Appium自动化测试基础 — uiautomatorviewer定位工具
Neon Optimization: About Cross access and reverse cross access
Set WordPress pseudo static connection (no pagoda)
golang 基础 —— 数据类型
Google released a security update to fix 0 days that have been used in chrome
Taro2.* 小程序配置分享微信朋友圈
js如何快速创建一个长度为 n 的数组
LeetCode:1175. 质数排列
Taro 小程序开启wxml代码压缩
C language instance_ three
c语言—数组
Comparison of picture beds of free white whoring
搭建【Redis in CentOS7.x】
uva 1401 dp+Trie
docker 方法安装mysql
今日问题-2022/7/4 lambda体中修改String引用类型变量