洛谷P2330 [SCOI2005]繁忙的都市——kruskal
给一手链接 https://www.luogu.com.cn/problem/P2330
这道题实质就是最小生成树
TIPS:最小生成树不仅是整体权值最小,也是最大边最小
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int M=2e5+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int n,m,ans;
struct node{int from,to,w;}e[M];
int cmp(node x,node y){return x.w<y.w;}
int f[M],T;
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
int main(){
n=read(); m=read(); T=n;
for(int i=;i<=n;i++) f[i]=i;
for(int i=;i<=m;i++) e[i].from=read(),e[i].to=read(),e[i].w=read();
sort(e+,e++m,cmp);
for(int i=;i<=m&&T>;ans=i,i++){
int p=find(e[i].from),q=find(e[i].to);
if(p==q) continue;
f[p]=q; T--;
}
printf("%d %d\n",n-,e[ans].w);
return ;
}
洛谷P2330 [SCOI2005]繁忙的都市——kruskal的更多相关文章
- 洛谷—— P2330 [SCOI2005]繁忙的都市
P2330 [SCOI2005]繁忙的都市 题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路 ...
- 洛谷 P2330 [SCOI2005]繁忙的都市
题目链接 https://www.luogu.org/problemnew/show/P2330 题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市 ...
- 洛谷 P2330 [SCOI2005]繁忙的都市(最小生成树)
嗯... 题目链接:https://www.luogu.org/problemnew/show/P2330 这道题的问法也实在是太模板了吧: 1.改造的道路越少越好 2.能够把所有的交叉路口直接或间接 ...
- 洛谷 P2330 [SCOI2005] 繁忙的都市 x
题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条 ...
- 洛谷P2330 [SCOI2005]繁忙的都市
#include<bits/stdc++.h> using namespace std; ; ; int n,k,Max,tot; struct node{ int cnt,fa; }f[ ...
- BZOJ 1083: [SCOI2005]繁忙的都市 kruskal
1083: [SCOI2005]繁忙的都市 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1083 Description 城市C是一个非 ...
- P2330 [SCOI2005] 繁忙的都市 洛谷
https://www.luogu.org/problem/show?pid=2330#sub 题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C ...
- [BZOJ1083] [SCOI2005] 繁忙的都市 (kruskal)
Description 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口 ...
- [LUOGU] P2330 [SCOI2005]繁忙的都市
题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条 ...
随机推荐
- 25.conda 下载安装与运用
转载:https://www.cnblogs.com/gandoufu/p/9748841.html https://blog.csdn.net/tuzixini/article/details/81 ...
- python学习笔记(7)容器以及容器的访问使用
一.容器 1.list列表 序列是python中最基本的数据结构,序列中的每个元素都分配一个数字,它的位置或索引,第一个索引是0,第二个索引是1,以此类推 Built-in mutable seque ...
- 【学习总结】SQL学习总结
参考链接: 菜鸟教程: 一.认识sql 二.sql语法 三.sql高级教程 四.sql函数 一.认识SQL SQL是什么? SQL 是用于访问和处理数据库的标准的计算机语言. SQL,指结构化查询语言 ...
- 04.Linux-CentOS系统sudo权限配置
visudo权限配置普通用户的使用权限范围配置文件: (请根据自己公司需求配置) [root@localhost ~]# visudo ## Allow root to run any command ...
- 记一次在mac上源码编译curl,使其支持NSS的过程
一.背景 在一次学习https原理的过程中,希望客户端指定特定的cipher suites来抓包分析SSL/TLS的握手过程,就想到了使用curl工具,而不是使用浏览器. 接下来使用man curl找 ...
- 获取用户真实IP:(模拟:客户端--F5--nginx--tomcat 后端获取用户真实IP)
模拟:客户端--F5--nginx--tomcat 后端获取用户真实IP 192.168.109.137 :nginx01(充当第一层代理==F5)192.168.109.138 :nginx02(二 ...
- POJ 2104 区间第k大(主席树)
题目链接:http://poj.org/problem?id=2104 题目大意:给定还有n个数的序列,m个操作,每个操作含有l,r,k,求区间[l,r]第k大 解题思路:线段树只能维护序列的最大值最 ...
- 前端VUE环境构建
https://nodejs.org/en/ 安装node 安装淘宝npm镜像 D:\>cd cnpm D:\cnpm>npm install -g cnpm --registry=htt ...
- 【leetcode】1047. Remove All Adjacent Duplicates In String
题目如下: Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent a ...
- Feign调用远程服务报错:Caused by: java.lang.IllegalStateException: Method getMemberInfo not annotated with HTTP method type (ex. GET, POST)
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ord ...