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

405 method not allowed appears when the third party jumps to the website

免费白嫖的图床对比

如何管理分布式团队?

Typical problems of subnet division and super network construction

AcWing 1148. 秘密的牛奶运输 题解(最小生成树)

AI 从代码中自动生成注释文档

移植DAC芯片MCP4725驱动到NUC980

Transformation transformation operator

2022 Google CTF SEGFAULT LABYRINTH wp

Dark horse notes - create immutable sets and streams
随机推荐
修改px4飞控的系统时间
ClickHouse字段分组聚合、按照任意时间段粒度查询SQL
LeetCode:1175. 质数排列
go-zero微服务实战系列(九、极致优化秒杀性能)
增加 pdf 标题浮窗
Yunna | work order management software, work order management software app
Today's question -2022/7/4 modify string reference type variables in lambda body
Body mass index program, entry to write dead applet project
2022 Google CTF SEGFAULT LABYRINTH wp
C language instance_ four
C # method of calculating lunar calendar date 2022
机器学习:随机梯度下降(SGD)与梯度下降(GD)的区别与代码实现。
AcWing 346. Solution to the problem of water splashing festival in the corridor (deduction formula, minimum spanning tree)
json学习初体验–第三者jar包实现bean、List、map创json格式
云呐|工单管理软件,工单管理软件APP
Receive user input, height BMI, BMI detection small business entry case
AcWing 1140. 最短网络 (最小生成树)
交叉验证如何防止过拟合
Taro 小程序开启wxml代码压缩
Typical problems of subnet division and super network construction