【Educational Codeforces Round 33 C】 Rumor
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
显然最后会形成多个集合,每个集合里面的人能够可以互相到达。
则维护并查集的时候,顺便维护一下每个集合里面的最小值就好。
最后答案就为∑min{每个集合}
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int f[N+10],mi[N+10],n,m;
bool bo[N+10];
int ff(int x){
if (f[x]==x) return x;
else return f[x] = ff(f[x]);
}
int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= n;i++){
cin >> mi[i];
f[i] = i;
}
for (int i = 1;i <= m;i++){
int x,y;
cin >> x >> y;
int r1 = ff(x),r2 = ff(y);
if (r1!=r2){
f[r1] = r2;
mi[r2] = min(mi[r2],mi[r1]);
}
}
long long ans = 0;
for (int i = 1;i <= n;i++){
int x = ff(i);
if (!bo[x]){
bo[x] = true;
ans += mi[x];
}
}
cout << ans << endl;
return 0;
}
【Educational Codeforces Round 33 C】 Rumor的更多相关文章
- 【Educational Codeforces Round 33 D】Credit Card
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每次遇到0的时候,看看当前累计的delta是多少. 如果大于0,则temp = d-delta; 小于0,取temp2 = min( ...
- 【Educational Codeforces Round 33 B】Beautiful Divisors
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把所有的那些数字打表出来. 逆序枚举就好 [代码] /* 1.Shoud it use long long ? 2.Have you ...
- 【Educational Codeforces Round 33 A】Chess For Three
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟题.知道哪个人是旁观者就好 [代码] /* 1.Shoud it use long long ? 2.Have you ever ...
- 【Educational Codeforces Round 37 F】SUM and REPLACE
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 那个D函数它的下降速度是很快的. 也就是说到最后他会很快的变成2或者1 而D(2)==2,D(1)=1 也就是说,几次操作过后很多数 ...
- 【Educational Codeforces Round 37 E】Connected Components?
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] bfs. 用一个链表来记录哪些点已经确定在某一个联通快里了. 一开始每个点都能用. 然后从第一个点开始进行bfs. 然后对于它的所有 ...
- 【Educational Codeforces Round 37 C】 Swap Adjacent Elements
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然l..r这一段连续的1可以把l..r+1变成有序的. 那么就把所有的连续1段变成有序的就好. 看看最后是不是升序即可. [代码] ...
- 【Educational Codeforces Round 37 B】 Tea Queue
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用一个队列来模拟排队就好. 队列放三元组(x,y,z) x表示人的下标,y和z分别表示进入和退出时间. 然后枚举时间从1到5000 ...
- 【Educational Codeforces Round 37 A】 Water The Garden
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 记录下水龙头在哪些位置. 然后每秒钟把index-i和index+i改变状态一下就好(置1 [代码] #include <bi ...
- 【Educational Codeforces Round 36 D】 Almost Acyclic Graph
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找到任意一个环. 然后枚举删掉其中的某一条边即可. (因为肯定要删掉这个环的,那么方法自然就是删掉其中的某一条边 (其它环,如果都包 ...
随机推荐
- MYSQL常用命令列表
MYSQL常用命令列表 1.系统管理 mysql -h主机地址 -u用户名 -p 连接MYSQL(在mysql/bin) exit 退出MYSQL命令 mysqladmin -u用户名 -p旧密码 p ...
- 【Henu ACM Round#18 A】 Multiplication Table
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 遍历i从1..n 看看x%i==0以及x/i<=n是否成立. [代码] #include <iostream> u ...
- ASP.NET中的几种弹出框提示
B/S不像C/S那样一个MessageBox就可以弹出提示框,不过可以通过js的“Alert”来弹出消息,或者通过一些变种的js方法.下面我给大家介绍几种,希望大家喜欢. 四种弹出框代码: prote ...
- Zookeeper vs. etcd
etcd是go语言实现的. 对比,可以参考这篇文章: http://studygolang.com/articles/4837 <服务发现:Zookeeper vs etcd vs Consul ...
- HDU 2563 统计问题 (DFS + 打表)
统计问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- PopupWindow的一些属性
void setOutsideTouchable(boolean touchable) Controls whether the pop-up will be informed ...
- 再谈怎样以最简单的方法将泛型为String类型的集合或String类型的数组转化为逗号间隔字符串形式
今天review代码,看见某些大爷在将泛型为String类型的集合或String类型的数组转化为逗号间隔字符串形式时仍然仅仅顾结果不注重过程,"大爷"咱能负点责任吗? 将泛型为St ...
- jquery11源码 animate() : 运动的方法
{ var fxNow, timerId, rfxtypes = /^(?:toggle|show|hide)$/, rfxnum = new RegExp( "^(?:([+-])=|)( ...
- Android SecurityException
public boolean checkNetwork() { boolean result = false; try { Context context = this.getApplicationC ...
- vuejs实现表格分页
http://www.cnblogs.com/landeanfen/p/6054654.html#_label3_8 <html xmlns="http://www.w3.org/19 ...