【题目描述】
城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造。城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条道路相连接。这些道路是双向的,且把所有的交叉路口直接或间接的连接起来了。每条道路都有一个分值,分值越小表示这个道路越繁忙,越需要进行改造。但是市政府的资金有限,市长希望进行改造的道路越少越好,于是他提出下面的要求: 1.改造的那些道路能够把所有的交叉路口直接或间接的连通起来。 2.在满足要求1的情况下,改造的道路尽量少。 3.在满足要求1、2的情况下,改造的那些道路中分值最大值尽量小。 作为市规划局的你,应当作出最佳的决策,选择那些道路应当被修建。 【输入】
第一行有两个整数n,m表示城市有n个交叉路口,m条道路。接下来m行是对每条道路的描述,u, v, c表示交叉路口u和v之间有道路相连,分值为c。(1≤n≤300,1≤c≤10000)。 【输出】
两个整数s, max,表示你选出了几条道路,分值最大的那条道路的分值是多少。 【输入样例】
4 5
1 2 3
1 4 5
2 4 7
2 3 6
3 4 8
【输出样例】
3 6
# include <bits/stdc++.h>
const int N = 1000 ;
const int M = N * N ;
using namespace std ;
int n , m ;
struct node {
int u ,v , w ;
}edge[M] ;
bool cmp(node x , node y) {
return x.w < y.w ;
}
int fa[N] ;
inline int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]) ;
}
inline void merge(int x , int y) {
fa[x] = y ; return ;
}
signed main() {
ios::sync_with_stdio(false) ;
cin >> n >> m ;
for(register int i=1;i<=n;i++) fa[i] = i ;
for(register int i=1;i<=m;i++) {
int u , v , w ;
cin >> u >> v >> w ;
edge[i] = {u , v , w} ;
}
int ans = 0 ; int _max = - 0x7f ;
sort(edge + 1 , edge + m + 1 , cmp) ;
for(register int i=1;i<=m;i++) {
int fx = find(edge[i].u) , fy = find(edge[i].v) ;
if(fx == fy) continue ;
merge(fx , fy) ; ans ++ , _max = max(_max , edge[i].w) ;
}
printf("%d %d" , ans , _max ) ;
return 0 ;
}

1392:繁忙的都市(city)的更多相关文章

  1. luogu p2330[SCOI05] 繁忙的都市——瓶颈生成树

    P2330 05四川 繁忙的都市 题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道 ...

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

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

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

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

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

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

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

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

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

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

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

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

  8. 【bzoj1083】[SCOI2005]繁忙的都市

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

  9. vijos P1190繁忙的都市(Kruskal)(最小生成树)

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

随机推荐

  1. Intel processor brand names-Xeon,Core,Pentium,Celeron----Atom

    http://en.wikipedia.org/wiki/Intel_atom Intel Atom From Wikipedia, the free encyclopedia   (Redirect ...

  2. webpack的安装个配置

    webpack在node下运行,首先先安装node 安装在全局:npm install webpack -g 在任何目录都可以运行 安装在局部:npm init -y npm install webp ...

  3. Cocos2d-x Vector——vector iterators incompatible

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  4. centos 7.xx 安装LAMP环境

    一.安装Apache 1.安装yum -y install httpd2.开启apache服务systemctl start httpd.service3.设置apache服务开机启动systemct ...

  5. notpad++快捷键

    Notpad++快捷键 Notepad++选中行操作 快捷键 使用技巧 作者: Rememberautumn 分类: 其他 发布时间: 2014-09-04 14:18 阅读: 60,106  微信小 ...

  6. Linux 及 CentOS系统安装

    VMware与Centos系统安装   今日任务 .Linux发行版的选择 .vmware创建一个虚拟机(centos) .安装配置centos7 .xshell配置连接虚拟机(centos) 选择性 ...

  7. hdfs namenode出错

    http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_design.html 健壮性 HDFS的主要目标就是即使在出错的情况下也要保证数据存储的可靠性.常见的三种出 ...

  8. vue-router-h5-history

    vue-router的HTML5 History 模式,这种模式充分利用 history.pushState API 来完成 URL 跳转而无须重新加载页面. const router = new V ...

  9. POJ3414 Pots —— BFS + 模拟

    题目链接:http://poj.org/problem?id=3414 Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  10. JQuery树形插件Dynatree的包装对象

    这是JQuery Dynatree插件的包装对象,做了些改进和增强,增加了右键菜单,以及相应事件等扩展1. [代码]MagicDTree的基本使用 <SCRIPT type=text/javas ...