CodeForces - 893C Rumor (并查集)

CANoe.Diva实战:基于CDD的UDS诊断自动化测试全流程解析 本文详细解析了使用CANoe.Diva进行基于CDD的UDS诊断自动化测试的全流程,包括环境搭建、CDD文件配置、测试范围设置、用例生成与验证、CANoe集成测试及报告分析。通过实战经验分享,帮助工程师快速掌握诊断自动化测试技巧,提升测试效率与质量。 阅读详情

原题地址: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.csdn.net/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;
}

 

 

一种基于频域滤波法消除干扰项与角谱法重构技术的数字全息显微台阶形貌测量实例分析 阅读详情

相关推荐

HAL库:中断处理函数 及 weak弱声明中断回调函数 详解

HAL库中断处理函数 及 weak弱声明中断回调函数

L_Z_J_I的博客 5183

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

STM32MP157+AD7606BSTZ四通道IEPE传感器采集方案实战(附完整电路图)

本文详细介绍了基于STM32MP157和AD7606BSTZ的四通道IEPE传感器采集方案,涵盖硬件电路设计、软件驱动开发及系统性能优化。通过精确的恒流源设计和同步采样技术,实现高精度振动信号采集,适用于工业振动监测等应用场景。

weixin_42713608的博客 732

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

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

suheyin的博客 469

无符号整数、带符号整数溢出问题

让我们详细讲解一下带符号整数溢出和无符号整数溢出问题中,符号标志位 (SF)、零标志位 (ZF) 和进位标志位 (CF) 的行为方式

weixin_49342084的博客 2096

二、频率调制光谱(FMS)技术——error信号的数学模型及其他推论

一些推论。

qq_41111336的博客 1612

注销账号方法

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

b451019486的专栏 4379

从音频录制到智能手表:Sigma-Delta ADC是如何在低功耗场景下‘欺骗’噪声的?

本文深入解析Sigma-Delta ADC在智能穿戴设备中的低功耗高精度实现原理,重点介绍其通过过采样和噪声整形技术‘欺骗’噪声的独特方法。以TWS耳机和医疗级健康监测为例,展示该技术如何在有限功耗预算下实现专业级信号采集,为消费电子设计提供关键解决方案。

weixin_30825581的博客 391

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的博客 1750

手把手教你用差分放大电路搭建LC振荡器(实测频率误差分析)

本文通过一个差分放大电路搭建LC振荡器的实践案例,深入分析了实测频率与理论值产生显著误差的原因。核心在于共模电感的互感效应改变了谐振回路的等效电感,导致频率偏差。文章提供了从电路搭建、误差根源剖析到波形优化与稳定性提升的完整解决方案,帮助电子爱好者深入理解模拟电路的实际行为。

svm4gardener的博客 555

基于FPGA的时间数字转换(TDC)设计(五:基于Carry4的高精度TDC设计)

基于FPGA的时间数字转换(TDC)设计,此为第五篇:基于Carry4的高精度TDC设计。提供工程文件及MATLAB测试分析代码

sdau2005的博客 8814

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的博客 867

把 ABAP ALV 表头做成两层分组:用 TOP-OF-PAGE 手工绘制双行列标题

摘要:本文介绍了在SAP ALV List中实现双层表头的方法。通过关闭系统默认列标题(no_colhead='X'),在TOP_OF_PAGE事件中手动绘制表头,使用sy-uline和sy-vline绘制线条实现分组效果。关键点包括:1)关闭系统表头;2)在事件处理中分两行输出分组标题和字段名;3)利用系统自动拼接线条的特性绘制表格边框。文中还指出了常见问题如线条自动粘连、颜色不生效等,并提供了完整示例代码和详细解释。这种方法适用于需要对字段进行业务分组的报表场景。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 283

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

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

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

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

并查集裸题 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

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

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的博客 350

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的博客 3669

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、付费专栏及课程。

余额充值
⌂ 换网址