我也不知道为什么我要来写这个…怕是写水题写上瘾了(bu

#include<cstdio>
#include<algorithm>
#define rep(i,n) for(register int i=1;i<=n;i++)
const int N=10005;
struct edge
{
int u,v,c;
}e[N];
int n,m,mx,s[N],pre[N];
inline int find(int x){return pre[x]==x?x:find(pre[x]);}
inline int max(int a,int b){return a>b?a:b;}
inline void unite(int x,int y)
{
int t=s[x]+s[y];
if(s[x]>s[y])pre[y]=x,s[x]=s[y]=t;
else pre[x]=y,s[x]=s[y]=t;
}
inline bool cmp(const edge &x,const edge &y)
{
return x.c<y.c;
}
int main()
{
scanf("%d%d",&n,&m);
rep(i,n)pre[i]=i,s[i]=1;
rep(i,m)scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].c);
std::sort(e+1,e+m+1,cmp);
rep(i,m)
{
int u,v,c;u=e[i].u;v=e[i].v;c=e[i].c;
int fu=find(u),fv=find(v);
if(fu==fv)continue;
unite(fu,fv);mx=max(mx,c);
}
printf("%d %d",n-1,mx);
}

[日常摸鱼]bzoj1083[SCOI2005]繁忙的都市-最小生成树的更多相关文章

  1. [BZOJ1083][SCOI2005]繁忙的都市 最小生成树

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1083 由kruskal算法原理可知,我们对一张无向图做普通的最小生成树,连上的最后一条边就 ...

  2. Bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)

    Bzoj 1083: [SCOI2005]繁忙的都市 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083 此题是最小瓶颈生成树的裸题. ...

  3. [BZOJ1083] [SCOI2005] 繁忙的都市 (kruskal)

    Description 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口 ...

  4. BZOJ1083: [SCOI2005]繁忙的都市

    水题之王SP…这题就裸的最小生成树 /************************************************************** Problem: 1083 User ...

  5. bzoj1083: [SCOI2005]繁忙的都市 瓶颈生成树

    https://www.lydsy.com/JudgeOnline/problem.php?id=1083 题意:给你一个图,求生成树最大边权最小值 就是求瓶颈生成树(生成树中最大边权最小),最小生成 ...

  6. 【最小瓶颈生成树】【最小生成树】【kruscal】bzoj1083 [SCOI2005]繁忙的都市

    本意是求最小瓶颈生成树,但是我们可以证明:最小生成树也是最小瓶颈生成树(其实我不会).数据范围很小,暴力kruscal即可. #include<cstdio> #include<al ...

  7. bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083 思路:连接所有点,肯定最少是需要n-1条边的,也就是写个最小生成树,记得保存下最大的权 ...

  8. [SCOI2005]繁忙的都市 (最小生成树)

    题目链接 Solution 裸的最小生成树. Code #include<bits/stdc++.h> using namespace std; const int maxn=500008 ...

  9. 【BZOJ1083】[SCOI2005]繁忙的都市(最小生成树)

    [BZOJ1083][SCOI2005]繁忙的都市(最小生成树) 题面 BZOJ 洛谷 题解 模板题. #include<iostream> #include<cstdio> ...

随机推荐

  1. python中操作数据库

    python中要操作数据库,要使用该数据库在python中对应的驱动库,本文介绍python操作mysql数据库 1.首先安装pymysql 2.导入库 3.建立连接 4.建立游标 5.发起请求 6. ...

  2. Contest 1445

    A \(a\) 中第 \(i\) 小的配 \(b\) 中第 \(i\) 大的. 限制相同,这样配最平均. 时间复杂度 \(O\left(tn\log n\right)\). B 最终的一百名至少是第一 ...

  3. Java基础教程——运算符

    运算符 算术运算符 加 减 乘 除 取余 自加 自减 + - * / % ++ -- public class 算术运算符 { public static void main(String[] arg ...

  4. 【线程池】自己声明临时线程池一定要shutdown!

    场景: 某个定时任务需要多线程执行,执行时间较久且每天只跑一次,想单独拉出一个线程池和其他业务隔离开,交给spring会导致核心线程一直存在 浪费线程资源,因此想单独拉一个池子用完就丢,原本想的是,在 ...

  5. codeforces 1424J,为了过这题,我把祖传的C++都用上了!

    大家好,我们选择的是Bubble Cup比赛Div2场次的J题,不用问我Bubble Cup是什么比赛,我也不清楚.总之是一场算法比赛就是了.可能是这个比赛知名度比较低吧,参与的人数也不是很多,我们选 ...

  6. OD断点操作

    原文链接:https://www.cnblogs.com/qiyeboy/p/6815988.html 在做Windows平台软件逆向时,Ollydbg是极其常用的逆向工具,动态调试功能非常强大.在调 ...

  7. 使用react终端运行npm start时报错

    npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! my-app@0.1.0 start: `react-scripts start` npm ERR ...

  8. Spring Boot 集成 MQTT

    本文代码有些许问题,处理方案见:解决 spring-integration-mqtt 频繁报 Lost connection 错误 一.添加配置 spring: mqtt: client: usern ...

  9. jquery on 动态生成绑定事件

    $(document).on("mouseenter", ".v6-div-kind-ok", function () { alert();});

  10. 20200311_解决Could not resolve host: mirrorlist.centos.org

    [root@localhost ~]# yum -y install wget 已加载插件:fastestmirror Determining fastest mirrors Could not re ...