嗯...

题目链接:https://www.luogu.org/problemnew/show/P2330

这道题的问法也实在是太模板了吧:

1.改造的道路越少越好

2.能够把所有的交叉路口直接或间接的连通起来

3.改造的那些道路中分值最大的道路分值尽量小

通过这些就可以判断出这是一道最小生成树的题(如果你还不了解最小生成树,请点击此网址查看:https://www.cnblogs.com/New-ljx/p/10779353.html)

思路:

就是一个最小生成树的模板,在最后将x点和y点合并的时候加上一个计数器cnt和一个maxn来保留最大值即可。

AC代码:

 #include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; int cnt, maxn;
int f[]; struct node{
int x, y, l;
} a[]; inline int cmp(node i, node j){
return i.l < j.l;
} inline int find(int x){
if(x != f[x])
f[x] = find(f[x]);
return f[x];
} int main(){
int n, m;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++){
scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].l);
}
for(int i = ; i <= n; i++){
f[i] = i;
}
sort(a+, a++m, cmp);
for(int i = ; i <= m; i++){
int r1 = find(a[i].x);
int r2 = find(a[i].y);
if(r1 != r2){
f[r1] = r2;
cnt++;//计数器
maxn = max(maxn, a[i].l);//保存最大值
}
}
printf("%d %d", cnt, maxn);
return ;
}

AC代码

洛谷 P2330 [SCOI2005]繁忙的都市(最小生成树)的更多相关文章

  1. 洛谷—— P2330 [SCOI2005]繁忙的都市

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

  2. 洛谷P2330 [SCOI2005]繁忙的都市——kruskal

    给一手链接 https://www.luogu.com.cn/problem/P2330 这道题实质就是最小生成树 TIPS:最小生成树不仅是整体权值最小,也是最大边最小 #include<cs ...

  3. 洛谷 P2330 [SCOI2005]繁忙的都市

    题目链接 https://www.luogu.org/problemnew/show/P2330 题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市 ...

  4. 洛谷 P2330 [SCOI2005] 繁忙的都市 x

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

  5. 洛谷P2330 [SCOI2005]繁忙的都市

    #include<bits/stdc++.h> using namespace std; ; ; int n,k,Max,tot; struct node{ int cnt,fa; }f[ ...

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

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

  7. P2330 [SCOI2005] 繁忙的都市 洛谷

    https://www.luogu.org/problem/show?pid=2330#sub 题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C ...

  8. [LUOGU] P2330 [SCOI2005]繁忙的都市

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

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

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

随机推荐

  1. Zookeeper 基础、工作流、ZAP协议

    ZooKeeper 基础 在深入了解ZooKeeper的运作之前,让我们来看看ZooKeeper的基本概念.[1] 我们将在本章中讨论以下主题:1.Architecture(架构)2.Hierarch ...

  2. 项目引入Solr时应该考虑的一些问题

    1.数据更新频率:每天数据增量有多大,随时更新还是定时更新 2.数据总量:数据要保存多长时间 3.一致性要求:期望多长时间内看到更新的数据,最长允许多长时间延迟 4.数据特点:数据源包括哪些,平均单条 ...

  3. Jmeter调度器配置

    Jmeter的线程组设置里有一个调配器设置,用于设置该线程组下脚本执行的开始时间.结束时间.持续时间及启动延迟时间.当需要半夜执行性能测试时会用到这个功能. ps:设置调度器配置,需要将前面的循环次数 ...

  4. 268. Missing Number序列中遗失的数字

    [抄题]: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...

  5. Free GIS Software

    Refer to There are lots of free gis software listed in the website: http://www.freegis.org/ http://w ...

  6. Flask框架 之 学生管理分析

    先看模板吧. index.html <body> <h1>学生列表</h1> <table border="1"> <thea ...

  7. Entity Framework Tutorial Basics(42):Colored Entity

    Colored Entity in Entity Framework 5.0 You can change the color of an entity in the designer so that ...

  8. Python基础入门-实现计算器多种姿势

    在Python中,虽然定义一个函数只需要def关键字,但是他能实现多种功能和用途,比如今天我们讲解的这几种方式.如何使用函数实现一个计算器的功能呢?当然,实现计算器的方式有很多种,我们举几个比较典型的 ...

  9. ios7适配--uitableviewcell选中效果

    ios7 UITableViewCell selectionStyle won't go back to blue up vote6down votefavorite 2 Xcode 5.0, iOS ...

  10. .net IAsyncResult 异步操作

    //定义一个委托 public delegate int DoSomething(int count); //BeginInvoke 的回调函数 private static void Execute ...