CodeForces - 893C Rumor (并查集)

10位PWM能否满足电梯±5mm平层精度?4位扩展法让10位PWM达到14位精度 电梯平层精度直接关系乘坐舒适性与安全性,而PWM分辨率是决定精度的关键因素之一。10位PWM能否满足±5mm的平层精度要求?本文从分辨率与物理量的对应关系出发,结合工程精度需求与实战对比,给出明确的选型结论与解决方案,请参考优快云博客《4位扩展法:基于ATtiny816的高精度PWM软件扩展方法》和《低成本高精度PWM:4位扩展法原理、实现和工程实践》。10位PWM的分辨率为 $2^{10} = 1024$ 级。 阅读详情

原题地址:http://codeforces.com/problemset/problem/893/C

 

C. Rumor
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.

Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.

Vova knows that there are n characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; i-th character wants ci gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.

The quest is finished when all n characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?

Take a look at the notes if you think you haven't understood the problem completely.

Input

The first line contains two integer numbers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of characters in Overcity and the number of pairs of friends.

The second line contains n integer numbers ci (0 ≤ ci ≤ 109) — the amount of gold i-th character asks to start spreading the rumor.

Then m lines follow, each containing a pair of numbers (xi, yi) which represent that characters xi and yi are friends (1 ≤ xi, yi ≤ n, xi ≠ yi). It is guaranteed that each pair is listed at most once.

Output

Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.

Examples
input
5 2
2 5 3 4 8
1 4
4 5
output
10
input
10 0
1 2 3 4 5 6 7 8 9 10
output
55
input y
10 5
1 6 2 7 3 8 4 9 5 10
1 2
3 4
5 6
7 8
9 10
output
15
Note

In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.

In the second example Vova has to bribe everyone.

In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters.

 

 

题意:

给出 n 个人和 m组关系 

告诉 编号从 1 ~ n 的人 传播谣言所需的金币数 

以及m组关系所对应的两人的编号

求出 最少需要多少金币 使得所有人都知道谣言

看到题目和样例  马上想到是并查集 但是 个人赛的时候并没有做出来(*  ̄︿ ̄)

 

参考 荆门王的博客:https://blog.youkuaiyun.com/qq_36258516/article/details/78787188

套用原先并查集的模板做的

放代码

#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define M 100005
int father[M];
long long mm[M];
int ff(int x)//获取父节点
{
    if (x!=father[x])
        father[x]=ff(father[x]);//路径压缩 修改的是father数组
    return father[x];
}
void join(int a,int b)//合并两个元素所在的集合
{
    int x,y;
    x=ff(a);
    y=ff(b);
    if (x!=y)
    {
        father[x]=y;
    }
}
int main()
{
    int t,n,m,a,b;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)//初始化并查集
        father[i]=i;
    for(int i=1; i<=n; i++)
        scanf("%lld",&mm[i]);
    for (int i=1; i<=m; i++)
    {
        scanf("%d%d",&a,&b);
        join(a,b);
    }
    for(int i=1; i<=n; i++)
        mm[ff(i)]=min(mm[ff(i)],mm[i]);//记录同一并查集中最小的权值
    long long sum=0;
    for(int i=1; i<=n; i++)
        if(i==ff(i))
            sum+=mm[i];
    printf("%lld\n",sum);
    return 0;
}

 

 

人形机器人电源系统硬件开发:从原理图设计到PCB布局的完整流程 人形机器人是“移动的智能终端”,其电源系统如同“心脏+血管”:既要为大脑(主控)、肌肉(电机)、感官(传感器)提供稳定能量,又要在有限体积内应对高动态负载(如跳跃时电机瞬间大电流)。本文聚焦“硬件开发”维度,覆盖从需求分析到PCB制板的完整流程,适合硬件工程师、机器人爱好者快速掌握工程实战方法。 阅读详情

相关推荐

【毕设课设】基于YOLO v3与LSTM的水位智能识别系统(附完整源码+数据集)

本文详细介绍了基于YOLO v3与LSTM的水位智能识别系统的完整实现方案。该系统通过YOLO v3精准定位水位尺数字,结合LSTM-OCR进行序列识别,并融合霍夫变换检测刻度线,实现高精度水位自动读取。项目提供了从环境搭建、模型训练到集成部署的全流程指南,并附有完整源码和数据集,是理想的毕设课设实战项目。

php55的博客 609

C - Rumor CodeForces - 893C

拆解流程的时候没想到res 开long long,但写的时候想到了,一开始还庆幸自己这次这么机灵,结果debug一直de不出错误点,还是靠学长提醒才发现printf没有用%lld。注意res开long long 后printf参数要改成%lld。自己总结的路径压缩find套路有瑕疵,一直没发现,也是靠学长指点才发现错误。cnt改为res ,res += v[i] 注意res要开long long。还有一开始用标准find然后tle,以后还是都用路径压缩find好了。标准un加一个值比较,小的做父节点。

m0_72496300的博客 230

2022网安保研经验帖

2022网安保研经验

fumingxiaoshen的博客 4894

CodeForces - 893C C - Rumor(并查集)

一:地址: http://codeforces.com/problemset/problem/893/C 二:分析:由题意知,人与人之间有自己的人际关系,每个人散播流言要的钱都不同,所以我们首先要借助人际关系建立我们的树模型(也就是并查集知识点啦)。再看题目要求输出的钱最少,那我们就考虑将每个树的根点弄成钱最少的那个人,最后计算每棵树(哪里不对)根点的人要的钱,累加即可。 三:wa点和注意点:

suheyin的博客 468

Python实战:5分钟搞定N-CMAPSS航空发动机数据集解析(附完整代码)

本文提供了一份针对N-CMAPSS航空发动机数据集的快速解析实战指南。通过Python的h5py和Pandas库,详细演示了如何高效读取HDF5格式文件、理解数据结构、提取关键特征(如传感器数据与剩余使用寿命RUL),并整合为可用于预测性维护分析的DataFrame,帮助研究者和工程师快速上手这一重要的工业时序数据集。

weixin_29083373的博客 278

分子动力学模拟学习1-采用AmberTools21的MCPB.py构建金属蛋白的top文件

分子动力学模拟学习1-采用AmberTools21的MCPB.py构建金属蛋白的top文件

weixin_45011386的博客 3823

注销账号方法

在注册优快云的时候必须激活账号才能正常使用。如果更改邮箱也需要重新激活,那么你只要更改邮箱不激活。3个月后, 你在优快云注册的账号就不能使用了。也就变相的注销了账号了。

b451019486的专栏 4375

基于STM32设计的指纹考勤机_348

随着信息化管理需求的日益增长,传统的人工考勤方式已难以满足现代社会对高效、精准和安全的考勤管理要求。为解决这一问题,本项目设计并实现了一款基于STM32的指纹考勤机系统。该系统采用AS608指纹识别模块进行人员身份识别,ESP8266无线模块实现与上位机APP的通信,支持人员信息录入、考勤时间段设置、考勤记录保存与查询等功能。系统通过SQLite数据库存储考勤数据,并提供导出EXCEL表格功能,方便数据管理与统计分析。该系统具有高效的考勤管理能力和良好的用户交互体验,能够广泛应用于企业、学校等机构的考勤管理

525

CodeForces - 893C Rumor(并查集,DFS)

Description Vova promised himself that he would never play computer games… But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it

riba2534的博客 1747

【Charge】仿真目录

Author: JiJi\textrm{Author: JiJi}Author: JiJi Created Time: 2026.01.20\textrm{Created Time: 2026.01.20}Created Time: 2026.01.20 Modified Time: 2026.01.20\textrm{Modified Time: 2026.01.20}Modified Time: 2026.01.20工作流程材料模型[Charge] 电荷分布与折射率变化理论 [Charge] FDTD

u011699626的博客 314

【BUG已解决】pip install 出现 error: Microsoft Visual C++ 14.0 or greater is required 解决方案

方案磁盘占用适用场景推荐指数安装Build Tools3-6GB长期Windows Python开发⭐⭐⭐⭐⭐寻找预编译wheel无额外占用只是想快速装上某个包⭐⭐⭐⭐⭐用conda安装视包而定已经在用conda环境⭐⭐⭐⭐⭐升级到新版本无额外占用库本身有更新的预编译版本⭐⭐⭐⭐使用WSL2需要额外配置Linux子系统频繁遇到Windows编译问题⭐⭐⭐⭐的核心是Windows 缺少本地 C/C++ 编译器,而目标包需要在本机编译。先看是否有捷径。

博客 1万+

Educational Codeforces Round 33 (Rated for Div. 2) C

Educational Codeforces Round 33 (Rated for Div. 2) C. Rumor time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Vova promised himself that he

ACM_e的博客 865

【车载以太网】【架构】整体架构与协议标准

车载以太网架构图 应用层:DHCP /SOMEIP/DoIP/XCP/UDPNM 传输层:TCP/IP 网络层:IPv4/IPv6/ARP/ICMP 链路层:IEEE Ethernet MAC+VLAN 物理层:Ethernet PHY: 100BASE-T1/1000BASE-T1/100BASE-Tx

专注汽车软件开发、AutoSAR、车载以太网、SOA、EE架构。 8354

Codeforces 893C Rumor (带权并查集)

C. Rumortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova promised himself that he would never play computer games... But recently Firestorm — ...

kolmikl 366

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Rumor CodeForces - 893C(并查集)

Vova promised himself that he would never play computer games… But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to

starlet_kiss的博客 350

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

并查集裸题 codeforces 893 C Rumor

题目链接 题意:有个散布谣言的人,要把一个谣言传给所有人,有的人相互之间是朋友(只要告诉其中一人,他的朋友就会知道),求最小花费。例如样例一,先告诉1(然后1会告诉4,4再告诉5),这样就只用再告诉2和3就行了,所以最小花费是2+5+3=10。 思路:并查集 #include&lt;iostream&gt; #include&lt;iomanip&gt; #include&lt;cstdi...

flyzer的博客 238

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

CodeForces - 893C Rumor 并查集

链接http://codeforces.com/problemset/problem/893/C C. Rumor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vova promised himself ...

JQM的博客 349

CodeForces - 893C Rumor【并查集】

<题目链接> 题目大意: 有n个人,其中有m对朋友,现在你有一个秘密你想告诉所有人,第i个人愿意出价a[i]买你的秘密,获得秘密的人会免费告诉它的所有朋友(他朋友的朋友也会免费知道),现在他们想出最少的价钱买秘密,那么你最少能得到多少钱? 解题分析: 题意很明显,就是求出每个块最低的价格,然后将这些价格相加就行,处理的时候,我们对并查集根的值进行更新,记录该根所对应块中的最低价...

weixin_30693183的博客 154

CodeForces - 893C-Rumor(并查集变式)

Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it...

weixin_30436891的博客 141

CodeForces - 893C Rumor(并查集)

C. Rumor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vova promised himself that he would never play com

←_← 412

Codeforces Educational Codeforces Round 33 C 893C Rumor(并查集)

C. Rumor time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Vova promised himself that he would never play computer games… But recently Fires

Lewis_Fehling的博客 613

Rumor CodeForces - 893C(并查集基本操作:维护连通块最值)

题目链接 PS:这题也可以用dfs搜连通块,一遍搜一遍记录连通块的最值。 AC代码: #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #define int long long using namespace std; const int maxn=1e5+6; int n,m,f[maxn],c[maxn]; int find_x(int x)

Alanrookie的博客 3665

codeforces 893 C.Rumor

Rumor time limit per test memory limit per test input output Vova promised himself that he would never play computer games… But recently Firestorm — a well-known ga...

WF830830的博客 175

CodeForces - 893 Educational Codeforces Round 33

文章目录1 A Chess For Three CodeForces - 893A1.1 题目大意1.2 解题思路1.3 代码实现2 B - Beautiful Divisors CodeForces - 893B2.1 题目大意2.2 解题思路2.3 代码实现3 C - Rumor CodeForces - 893C3.1 题目大意3.2 解题思路3.3 代码实现4 D - Credit Car...

林夕 312

Codeforces 893 Rumor 并查集/DFS

  题目链接:http://codeforces.com/contest/893/problem/C   题目描述:你可以收买每一个人,收买他之后相当于收买了他所有的朋友(双向的),问最少多少钱可以收买到所有人。   解题思路: 典型的并查集, 自己看到这题就知道该怎么做, 无奈没有学习过图论, 就拿DFS做的, T掉了, 因为我很多重复的边都存进去了, 然后看别人的博客又学习到了新的姿势...

weixin_33922670的博客 112
上一篇: %I64d 和%lld 的区别
下一篇: 快速计算x的n次幂 power()的实现
OneLine_
博客等级 码龄9年 48粉丝 72原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值