bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083
思路:连接所有点,肯定最少是需要n-1条边的,也就是写个最小生成树,记得保存下最大的权值就好了
实现代码:
#include<bits/stdc++.h>
using namespace std; const int M = 3e4+;
int f[M],cnt; struct node{
int u,v,w;
}e[]; bool cmp(node a,node b){
return a.w < b.w;
} int Find(int x){
if(x == f[x]) return x;
return f[x] = Find(f[x]);
} int main()
{
int ans= ,n, m;
cin>>n>>m;
for(int i = ;i <= m;i ++){
cin>>e[i].u>>e[i].v>>e[i].w;
}
sort(e+,e++m,cmp);
for(int i = ;i <= n;i ++) f[i] = i;
for(int i = ;i <= m;i ++){
int fx = Find(e[i].u),fy = Find(e[i].v);
if(fx != fy){
f[fy] = fx;
ans = e[i].w;
}
}
cout<<n-<<" "<<ans<<endl;
}
bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)的更多相关文章
- Bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)
Bzoj 1083: [SCOI2005]繁忙的都市 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083 此题是最小瓶颈生成树的裸题. ...
- BZOJ 1083: [SCOI2005]繁忙的都市【Kruscal最小生成树裸题】
1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2925 Solved: 1927[Submit][Sta ...
- BZOJ 1083: [SCOI2005]繁忙的都市 kruskal
1083: [SCOI2005]繁忙的都市 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1083 Description 城市C是一个非 ...
- BZOJ 1083: [SCOI2005]繁忙的都市(MST)
裸的最小生成树..直接跑就行了 ---------------------------------------------------------------------- #include<c ...
- BZOJ 1083 [SCOI2005]繁忙的都市
1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1664 Solved: 1080[Submit][Sta ...
- BZOJ 1083 [SCOI2005]繁忙的都市 (最小生成树裸题无重边) 超简单写法!!
Description 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口 ...
- BZOJ 1083: [SCOI2005]繁忙的都市 裸的最小生成树
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1083 代码: #include<iostream> #include< ...
- BZOJ(5) 1083: [SCOI2005]繁忙的都市
1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4105 Solved: 2595[Submit][Sta ...
- 1083: [SCOI2005]繁忙的都市
1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1319 Solved: 878[Submit][Stat ...
随机推荐
- [LeetCode] Department Highest Salary -- 数据库知识(mysql)
184. Department Highest Salary The Employee table holds all employees. Every employee has an Id, a s ...
- Python-每日习题-0009-time
题目:暂停一秒输出 程序分析:使用 time 模块的 sleep() 函数. import time for i in range(4): print(str(int(time.time()))[-2 ...
- hana-banach定理
1. x1不是X除开G以外所有的空间 2.如果极大元不是全空间的话,根据前面的讨论,还可以延拓,这就和极大矛盾了
- linux中mariadb的安装
在Linux中mariaDB的安装 MariaDB其实就是MySQL的分支,是为了应对MySQL的即将的闭源风险所产生的. Linux系统中软件包的格式为mysql.rpm格式. 通过yum去安装 L ...
- c# Mongodb两个字段不相等 MongoDB原生查询
var document = new BsonDocument{ { "$where","this.StarTime!=this.EndTime"}, { }, ...
- pip ipython启动错误 Fatal error in launcher: Unable to create process using
完整的错误提示: C:\Users\yyy>ipython3Fatal error in launcher: Unable to create process using '"c:\u ...
- 理解npm、nvm、nodejs之间的关系
nvm nvm:nodeJs版本管理工具,管理nodejs版本和npm版本,使用nvm安装nodejs时会将npm一起安装下来 nodejs nodeJs: 一种高效的JavaScript运行环境 n ...
- [转帖]分布式Unique ID的生成方法一览
分布式Unique ID的生成方法一览 http://www.importnew.com/22211.html 分布式的Unique ID的用途如此广泛,从业务对象Id到日志的TraceId,本文总结 ...
- CMake--List用法
list(LENGTH <list><output variable>) list(GET <list> <elementindex> [<ele ...
- Django--CRM--一级, 二级 菜单表
一. 一级菜单表 1. 首先要修改权限表的字段, 在权限表下面加上icon和 is_menu 的字段 2. 展示结果 # 我们既然想要动态生成一级菜单,那么就需要从数据库中拿出当前登录的用户的菜单表是 ...