[BZOJ1083][SCOI2005]繁忙的都市 最小生成树
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1083
由kruskal算法原理可知,我们对一张无向图做普通的最小生成树,连上的最后一条边就是答案。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int inline readint(){
int Num;char ch;
while((ch=getchar())<''||ch>'');Num=ch-'';
while((ch=getchar())>=''&&ch<='') Num=Num*+ch-'';
return Num;
}
int N,M;
struct EDGE{
int u,v,w;
bool operator < (const EDGE &_)const{
return w<_.w;
}
}edge[];
int fa[];
int inline getfa(int x){
return fa[x]==x?x:fa[x]=getfa(fa[x]);
}
int main(){
N=readint();
printf("%d ",N-);
M=readint();
for(int i=;i<=M;i++){
edge[i].u=readint();
edge[i].v=readint();
edge[i].w=readint();
}
sort(edge+,edge++M);
for(int i=;i<=N;i++) fa[i]=i;
int tot=;
for(int i=;i<=M;i++){
int fu=getfa(edge[i].u),
fv=getfa(edge[i].v);
if(fu==fv) continue;
fa[fu]=fv;
tot++;
if(tot+==N){
printf("%d\n",edge[i].w);
return ;
}
}
}
[BZOJ1083][SCOI2005]繁忙的都市 最小生成树的更多相关文章
- [日常摸鱼]bzoj1083[SCOI2005]繁忙的都市-最小生成树
我也不知道为什么我要来写这个-怕是写水题写上瘾了(bu #include<cstdio> #include<algorithm> #define rep(i,n) for(re ...
- Bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)
Bzoj 1083: [SCOI2005]繁忙的都市 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083 此题是最小瓶颈生成树的裸题. ...
- 【最小瓶颈生成树】【最小生成树】【kruscal】bzoj1083 [SCOI2005]繁忙的都市
本意是求最小瓶颈生成树,但是我们可以证明:最小生成树也是最小瓶颈生成树(其实我不会).数据范围很小,暴力kruscal即可. #include<cstdio> #include<al ...
- BZOJ1083: [SCOI2005]繁忙的都市
水题之王SP…这题就裸的最小生成树 /************************************************************** Problem: 1083 User ...
- [BZOJ1083] [SCOI2005] 繁忙的都市 (kruskal)
Description 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口 ...
- bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083 思路:连接所有点,肯定最少是需要n-1条边的,也就是写个最小生成树,记得保存下最大的权 ...
- bzoj1083: [SCOI2005]繁忙的都市 瓶颈生成树
https://www.lydsy.com/JudgeOnline/problem.php?id=1083 题意:给你一个图,求生成树最大边权最小值 就是求瓶颈生成树(生成树中最大边权最小),最小生成 ...
- [SCOI2005]繁忙的都市 (最小生成树)
题目链接 Solution 裸的最小生成树. Code #include<bits/stdc++.h> using namespace std; const int maxn=500008 ...
- 【BZOJ1083】[SCOI2005]繁忙的都市(最小生成树)
[BZOJ1083][SCOI2005]繁忙的都市(最小生成树) 题面 BZOJ 洛谷 题解 模板题. #include<iostream> #include<cstdio> ...
随机推荐
- 【Linux编程】进程终止和exit函数
内核要运行一个应用程序,唯一的途径是通过系统调用.exec函数.exec又会调用启动程序,启动程序(一般是汇编语言)以类似以下的方式调用main函数: void exit(main(argc, arg ...
- Ubuntu14.04常用安装
sudo apt-get update sudo apt-get install flashplugin-nonfree ================= 类飞秋软件 sudo apt-get in ...
- 2012年公司组织旅游西安线个人记录(repost)
2012年公司组织旅游西安线个人记录 文件夹 [隐藏] 1 序言 2 第1天 3 第2天 4 第3天 5 第4天 6 第5天 [title=2012%E5%B9%B4%E5%85%AC%E5%8F% ...
- base64和图片互转
pom.xml添加 <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --> <dependen ...
- CocoaPoda在iOS开发中的使用
CocoaPoda在iOS开发中的使用 CocoaPods 简介 CocoaPods是iOS开发中不可避免的依赖管理第三方的工具,能简化一些第三方库文件需要添加编译参数及依赖库的繁复工作 CocoaP ...
- 大话设计模式C++实现-第14章-观察者模式
一.UML图 关键词:Subject维护一个Observer列表.Subject运行Notify()时就运行列表中的每一个Observer的Update(). 二.概念 观察者模式:定义了一种一对多的 ...
- 基于websocket的单聊.群聊
关于ai.baidu.com的 代码: #########################################核心代码################################### ...
- Delphi的函数指针
不求全面,先留个爪: TNotifyEvent = procedure(Sender: TObject) of object; TMethod = record Code, Data: Pointer ...
- jsp实现翻页功能
jsp实现翻页功能 要实现翻页功能,只需要设置一个pageIndex即可,然后每次加载页面时通过pageIndex去加载数据就行. 那么我们可以设置一个隐藏的input框,用于传递pageIndex给 ...
- Logistic回归 线性回归(转)
来源: http://www.cnblogs.com/jerrylead 1 摘要 本报告是在学习斯坦福大学机器学习课程前四节加上配套的讲义后的总结与认识.前四节主要讲述了回归问题,回归属于有监督学习 ...