Bzoj 1083: [SCOI2005]繁忙的都市

题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083

此题是最小瓶颈生成树的裸题.

最小瓶颈生成树:由最小的边权的\(n-1\)条边连接起\(n\)个点.

显然这就是\(Kruskal\)算法.继而得知其实就是求最小生成树,用\(prim\)也可以求.

然后这道题就成了最小生成树入门题??

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#define max(a,b) a > b ? a : b
const int maxN = 300 + 7;
const int maxM = 5e4 + 7;
using namespace std; struct Node {
int u,v,w;
}Map[maxM];
int num ;
int f[maxN]; bool cmp(Node a,Node b) {
return a.w < b.w;
} void add_Node(int u,int v,int w) {
Map[++ num].u = u;
Map[num].v = v;
Map[num].w = w;
return;
} int find(int x) {
return f[x] == x ? x : f[x] = find(f[x]);
} void unit(int u,int v) {
int fx = find(u),fy = find(v);
if(rand() % 2) f[fx] = fy;
else f[fy] = fx;
return;
} inline int read() {
int x = 0,f = 1;char c = getchar();
while(c < '0' || c > '9') {if(c == '-')f = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = getchar();}
return x * f;
} int main() {
int n,m;
n = read();m = read();
for(int i = 1;i <= n;++ i)
f[i] = i;
for(int i = 1,u,v,w;i <= m;++ i) {
u = read();v = read();w = read();
add_Node(u,v,w);
}
sort(Map + 1,Map + m + 1,cmp);
int sum = 0,k = 0;
for(int i = 1;i <= m;++ i) {
if(k == n - 1) break;
int fx = find(Map[i].u),fy = find(Map[i].v);
if(fx != fy) {
k ++;
sum = max(Map[i].w,sum);
unit(Map[i].u,Map[i].v);
}
}
printf("%d %d",n - 1,sum);
return 0;
}


Bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)的更多相关文章

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

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

  2. BZOJ 1083: [SCOI2005]繁忙的都市【Kruscal最小生成树裸题】

    1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2925  Solved: 1927[Submit][Sta ...

  3. BZOJ 1083: [SCOI2005]繁忙的都市 kruskal

    1083: [SCOI2005]繁忙的都市 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1083 Description 城市C是一个非 ...

  4. BZOJ 1083: [SCOI2005]繁忙的都市(MST)

    裸的最小生成树..直接跑就行了 ---------------------------------------------------------------------- #include<c ...

  5. BZOJ 1083 [SCOI2005]繁忙的都市

    1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1664  Solved: 1080[Submit][Sta ...

  6. BZOJ 1083 [SCOI2005]繁忙的都市 (最小生成树裸题无重边) 超简单写法!!

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

  7. BZOJ 1083: [SCOI2005]繁忙的都市 裸的最小生成树

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1083 代码: #include<iostream> #include< ...

  8. BZOJ(5) 1083: [SCOI2005]繁忙的都市

    1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4105  Solved: 2595[Submit][Sta ...

  9. 1083: [SCOI2005]繁忙的都市

    1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1319  Solved: 878[Submit][Stat ...

随机推荐

  1. 理解:return、break、continue区别

    1.return:结束该方法的执行 2.continue:结束当前流程中的continue一下的代码,如果是for循环会再次执行下一个条件 3.break:完全终止当前执行流程,如果是for循环,那么 ...

  2. ES6入门系列二(数值的扩展)

    ES6 在 Number对象上新增了很多方法 1 .    Number.isFinite()判断是否为有限的数字 和全局的isFinite() 方法的区别是 isFinite('1') === tr ...

  3. 使用命令动态更新JAR包中的文件

    动态更新JAR包中的文件,经本人实际测试可正常执行! 一.查询jar包中要替换的文件位置 jar  -tvf  gateway.jar  |  grep  topjui.config.js 二.在当前 ...

  4. 解决https接口 以及谷歌错误

    <meta http-equiv="Content-Security-Policy" content="block-all-mixed-content"& ...

  5. 086 Partition List 分隔链表

    给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前.你应当保留两个分区中每个节点的初始相对位置.例如,给定1->4->3->2-&g ...

  6. django modelform中的self.instance

    在stackoverflow上看到一个问题,正好是我疑惑很久的相关问题. [原问题地址]https://stackoverflow.com/questions/18265023/self-instan ...

  7. JAVA-汉字转换成汉语拼音(pinyin4j-2.5.0-sources.jar)

    在项目中,经常会使用汉语拼音,特别是把汉字转换成汉语拼音.下面给出一种常用的工具. 在使用该程序必须添加 pinyin4j-2.5.0-sources.jar包. import net.sourcef ...

  8. WebService学习之旅(四)Apache Axis2的安装

    一.Axis2简介 Axis2是目前使用较多的WebService引擎,它是Axis1.x的升级版本,不仅支持SOAP1.1和SOAP1.2,而且也提供了对REST风格WebService的支持. A ...

  9. WebService学习之旅(一)使用JAX-WS发布WebService

    JAX-WS全称Java™ API for XML Web Services,是随着JDK1.6及其后续版本发布的方便Java程序员开发WebService应用的一组API,通常简称为JWS,目前版本 ...

  10. java.lang.IllegalArgumentException: name MUST NOT NULL! at org.nutz.dao.impl.NutDao.fetch

    Nutz传值报错问题 作者:Vashon 时间:20150902 平台:Nutz框架 Java后台方法中拿值时报的错 报错信息: java.lang.IllegalArgumentException: ...