[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> ...
随机推荐
- android 不同进程间的调用 AIDL 实现通讯服务
android 不同进程间的调用 AIDL 实现通讯服务 近期对aidl android 不同进程间的调用,不同运用间的调用做了一些尝试: 过程例如以下: 1:首先在要被调用的程序里写好 ...
- hadoop生态系统学习之路(十)MR将结果输出到hbase
之前讲了MR将结果输出到hdfs.hive.db,今天再给大家分享一下,怎样将结果输出到hbase. 首先,提一句,笔者在hadoop集群运行此MR的时候报了一个错误.是一个jar包的缘故,这个错误是 ...
- Python标准库:内置函数complex([real[, imag]])
本函数能够使用參数real + imag*j方式创建一个复数.也能够转换一个字符串的数字为复数:或者转换一个数字为复数.假设第一个參数是字符串,第二个參数不用填写.会解释这个字符串且返回复数.只是,第 ...
- 【MongoDB】The description of procedure in MongoDB
In this blog the procedure of mongodb will be described in details. It is known that mongodb has pro ...
- 最新Bootstrap手册
http://www.jqhtml.com/bootstraps-syntaxhigh/index.html
- 【扩展知识2】函数strlen()和非函数sizeof的使用
[扩展知识2]函数strlen()和非函数sizeof的使用 [扩展文件夹] strlen函数 sizeof ( 1 )函数strlen() 原型:size_tstrlen ( const char ...
- Django 使用UEditor
Django package 的一些包不支持upload file, 而且 有几个支持的不是收费的就是要开csrf ,这对于苦逼程序猿来说始终是件恼火的事.所以经过查阅各种资料.看了各种各样的配置do ...
- ABAP 读取服务器CSV文件到内表
DATA: BEGIN OF gs_data , cola TYPE string, colb TYPE string, ... END OF gs_data, gt_data LIKE TABLE ...
- POJ1177 Picture —— 求矩形并的周长 线段树 + 扫描线 + 离散化
题目链接:https://vjudge.net/problem/POJ-1177 A number of rectangular posters, photographs and other pict ...
- html页面缓存问题
若IIS没有设置,html页面一旦缓存,则永远缓存. Chrome如下 火狐如下 一种方法:我们一般通过xxx.html?20151010这样URL欺骗浏览器. 另一种方法:设置IIS,让永远客户端不 ...