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

思路:连接所有点,肯定最少是需要n-1条边的,也就是写个最小生成树,记得保存下最大的权值就好了

实现代码:

#include<bits/stdc++.h>
using namespace std; const int M = 3e4+;
int f[M],cnt; struct node{
int u,v,w;
}e[]; bool cmp(node a,node b){
return a.w < b.w;
} int Find(int x){
if(x == f[x]) return x;
return f[x] = Find(f[x]);
} int main()
{
int ans= ,n, m;
cin>>n>>m;
for(int i = ;i <= m;i ++){
cin>>e[i].u>>e[i].v>>e[i].w;
}
sort(e+,e++m,cmp);
for(int i = ;i <= n;i ++) f[i] = i;
for(int i = ;i <= m;i ++){
int fx = Find(e[i].u),fy = Find(e[i].v);
if(fx != fy){
f[fy] = fx;
ans = e[i].w;
}
}
cout<<n-<<" "<<ans<<endl;
}

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

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

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

  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. sort 快排解决百万级的排序

    问题:给n个整数,按从大到小的顺序,输出前m大的整数0<m,n<1000000,每个整数[-500000,500000]输入:5 33 -35 92 213 -644输出:213 92 3 ...

  2. 543A - Writing Code(二维动态规划)

    题意:现在要写m行代码,总共有n个文件,现在给出第i个文件每行会出现v[i]个bug,问你在bug少于b的条件下有多少种安排 分析:定义dp[i][j][k],i个文件,用了j行代码,有k个bug 状 ...

  3. c++入门之出话指针和地址。

    指针和地址是c和c++中重要的概念,在此,对指针做以下几方面的总结: new和delete: ]; point[] = ; point[] = ; point[] = ; cout << ...

  4. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.bw.mapper.BillMapper.getBillList at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:225

    这个错误是没有找到映射文件 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.b ...

  5. WebSocket实现一个聊天室

    聊天室页面-->index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...

  6. python中$和@基础笔记

    python 2.4以后,增加了@符号修饰函数对函数进行修饰,python3.0/2.6又增加了对类的修饰. $ 在正则表达式中,匹配一个字符串的末尾.(参考http://www.runoob.com ...

  7. js创建并下载文件

    先上代码: function createAndDownloadFile(fileName, content) { var aTag = document.createElement('a'); va ...

  8. Oracle查询数据库编码

    select userenv('language') from dual

  9. rpm和yum

    RMP(红帽软件包管理器) RPM有点像Windows系统中的控制面板,会建立统一的数据库文件,详细记录软件信息并能够自动分析依赖关系. YUM(软件仓库)

  10. Netty ByteBuf和Nio ByteBuffer

    参考https://blog.csdn.net/jeffleo/article/details/69230112 一.简介 Netty中引入了ByteBuf,它相对于ByteBuffer来说,带来了很 ...