洛谷P2330 [SCOI2005]繁忙的都市
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
const int maxm=;
int n,k,Max,tot;
struct node{
int cnt,fa;
}f[maxn];
int find(int x){return f[x].fa==x?x:f[x].fa=find(f[x].fa);}
void Union(int x,int y)
{
x=find(x),y=find(y);if(x==y) return;
if(f[x].cnt<=f[y].cnt) {f[x].fa=y;f[y].cnt+=f[x].cnt;}
else {f[y].fa=x;f[x].cnt+=f[y].cnt;}
}
struct edge{
int x,y,dis;
}E[maxm];
inline bool cmp(const edge &a,const edge &b) {return a.dis<b.dis;}
int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=k;i++) scanf("%d%d%d",&E[i].x,&E[i].y,&E[i].dis);
for(int i=;i<=n;i++) f[i].fa=i,f[i].cnt=;
sort(E+,E++k,cmp);
for(int i=;i<=k;i++)
{
if(f[find()].cnt==n) break;
if(find(E[i].x)!=find(E[i].y)) Union(E[i].x,E[i].y),++tot,Max=max(Max,E[i].dis);
}
printf("%d %d",tot,Max);
return ;
}
洛谷P2330 [SCOI2005]繁忙的都市的更多相关文章
- 洛谷—— 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]繁忙的都市——kruskal
给一手链接 https://www.luogu.com.cn/problem/P2330 这道题实质就是最小生成树 TIPS:最小生成树不仅是整体权值最小,也是最大边最小 #include<cs ...
- P2330 [SCOI2005] 繁忙的都市 洛谷
https://www.luogu.org/problem/show?pid=2330#sub 题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C ...
- [LUOGU] P2330 [SCOI2005]繁忙的都市
题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条 ...
- 【BZOJ1083】[SCOI2005]繁忙的都市(最小生成树)
[BZOJ1083][SCOI2005]繁忙的都市(最小生成树) 题面 BZOJ 洛谷 题解 模板题. #include<iostream> #include<cstdio> ...
- BZOJ 1083: [SCOI2005]繁忙的都市 kruskal
1083: [SCOI2005]繁忙的都市 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1083 Description 城市C是一个非 ...
随机推荐
- springMVC原理解析
1:SpringMVC运行原理 2:工作流程 (1)客户端(浏览器)发送请求,直接请求到DispatcherServlet. (2)DispatcherServlet根据请求信息调用HandlerMa ...
- 学习线程池源码--ThreadPoolExecutor
1 创建ThreadPoolExecutor ThreadPollExecutor有四个构造函数,但本质上都是调用这一个构造函数. public ThreadPoolExecutor(int core ...
- js封装ajax的方法
常用的ajax请求方法封装 /** * ajax请求的封装代码 */ function ajaxPost(url, params, cb) { $.ajax({ type : 'post', url ...
- python实例 输出你好
#打开新窗口,输入: #! /usr/bin/python # -*- coding: utf8 -*- s1=input("Input your name:") print(&q ...
- 洛谷 3112 [USACO14DEC]后卫马克Guard Mark——状压dp
题目:https://www.luogu.org/problemnew/show/P3112 状压dp.发现只需要记录当前状态的牛中剩余承重最小的值. #include<iostream> ...
- hdu 1358 Period(KMP入门题)
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- from和modelform的用法和介绍
from和modelform的用法和介绍 一 form 1. form的作用 1. 生成HTML代码 2. 帮我们做数据有效性的校验 3. 保留上次输入内容,显示错误提示 2. form组件校验数 ...
- hackerrank--- challenges/fp-update-list
纯属为了练习haskell, 竟然贴代码都没办法高亮. challenges/fp-update-list Update the values of a list with their absolut ...
- database homework1
mysql> select * from teacher_info; +----+------+-----+--------+---------+ | id | name | age | sal ...
- FastAdmin 自学教程 - 目录(持续更新)(2019-10-11)
FastAdmin 自学教程 - 目录 本自学教程将不定期更新. 了解 FastAdmin FastAdmin 开发第 1 天:了解 FastAdmin 框架 FastAdmin 开发第 2 天:安装 ...