codeforces 445 B DZY Loves Chemistry【并查集】
题意:给出n种化学物质,其中m对会发生化学反应,每次加入化学物质进去的时候,
如果有能够和它发生反应的,危险值就乘以2,问怎样的放入顺序使得危险值最大
将这m对会反应的用并查集处理,统计每个连通块里面的元素个数,再将其减去1,加起来,就是2的指数
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int p[maxn];
vector<int> g[maxn]; int find(int x){ return x==p[x]? x:p[x]=find(p[x]);} LL pow_my(int x){
LL ans=;
for(int i=;i<=x;i++) ans=(LL)ans*;
return ans;
} int main(){
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++) p[i]=i; while(m--){
int u,v;
cin>>u>>v;
int x=find(u);
int y=find(v);
if(x!=y) p[x]=y;
} for(int i=;i<=n;i++){
int x=find(i);
g[x].push_back(i);
} int ans=;
for(int i=;i<=n;i++){
if(g[i].size()!=) ans+=g[i].size()-;
} cout<<pow_my(ans)<<"\n"; return ;
}
codeforces 445 B DZY Loves Chemistry【并查集】的更多相关文章
- UOJ_14_【UER #1】DZY Loves Graph_并查集
UOJ_14_[UER #1]DZY Loves Graph_并查集 题面:http://uoj.ac/problem/14 考虑只有前两个操作怎么做. 每次删除一定是从后往前删,并且被删的边如果不是 ...
- UOJ14 DZY Loves Graph 并查集
传送门 题意:给出一张$N$个点,最开始没有边的图,$M$次操作,操作为加入边(边权为当前的操作编号).删除前$K$大边.撤销前一次操作,每一次操作后询问最小生成树边权和.$N \leq 3 \tim ...
- cf444E. DZY Loves Planting(并查集)
题意 题目链接 Sol 神仙题啊Orzzzzzz 考场上的时候直接把树扔了对着式子想,想1h都没得到啥有用的结论. 然后cf正解居然是网络流??出给NOIP模拟赛T1???¥%--&((--% ...
- Codeforces 445 A DZY Loves Chessboard【DFS】
题意:给出n*m的棋盘,在‘.’处放上B或者W,最后要求所有的B和W都不相邻 先把棋盘的点转化成‘B’,再搜,如果它的四周存在‘B’,则将它变成'W' 一直挂在第五个数据的原因是,没有dfs(nx,n ...
- CodeForces 445B DZY Loves Chemistry
DZY Loves Chemistry Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- CodeForces 445B. DZY Loves Chemistry(并查集)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://codeforces.com/problemset/prob ...
- CF 445B DZY Loves Chemistry(并查集)
题目链接: 传送门 DZY Loves Chemistry time limit per test:1 second memory limit per test:256 megabytes D ...
- Codeforces Round #254 (Div. 2)B. DZY Loves Chemistry
B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #254 (Div. 2):B. DZY Loves Chemistry
B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- 极客时间 Mysql实战45讲 07讲行锁功过:怎么减少行锁对性能的影响笔记 极客时间
极客时间 Mysql实战45讲 07讲行锁功过:怎么减少行锁对性能的影响笔记 极客时间极客时间 Mysql实战45讲 07讲行锁功过:怎么减少行锁对性能的影响笔记 极客时间 笔记体会: 方案一,事务相 ...
- BZOJ 3339 线段树
思路: 考虑离线处理 显然 l固定时 r越大 ans越大 那我们不妨按照l从小到大排序 l->l+1的时候 l到next[l]这段区间都跟a[l]取min就好了 搞颗线段树维护一下 //By S ...
- C++之虚函数表
本文引自:http://songlee24.github.io/blog/2014/09/02/c-plus-plus-jin-jie-zhi-xu-han-shu-biao/ C++通过继承(inh ...
- asp.net HTTP请求过程
http://blog.csdn.net/zxxSsdsd/article/details/51909860
- js中es5 使用call方法继承实现 1.0
function Parent(name){ this.name = name; this.showMess = function(){ return this.name; } } Parent.pr ...
- category和关联对象
如上所见,我们知道在category里面是无法为category添加实例变量的.但是我们很多时候需要在category中添加和对象关联的值,这个时候可以求助关联对象来实现. MyClass+Categ ...
- ZBrush雕刻生物小技巧
本教程主要学习如何使用ZBrush®3D图形绘制软件的工具和笔刷雕刻酷酷的生物造型,我们今天来看看在游戏.媒体和电视领域有着十几年丰富经验的3D角色艺术家Francis-Xavier Martins是 ...
- 路飞学城Python-Day18
[1.编程范式] 1.面向过程编程 2.面向对象编程 [2.面向过程编程] 面向过程:核心就是过程 什么是过程? 过程指的是解决问题的步骤,先做什么,在作什么,面向过程就像是设计一个流水线,是一种 ...
- .NET 拼音汉字转化(全面)
引言 这是一个.NET 用C#语言编写的 拼音转汉字类,考虑到有很多拼音转汉字,但是试用过发现大部分有很多生僻字都没有办法显示.在此分享一个支持绝大多数的较为全面的拼音汉字转化帮助类.不多说,代码附 ...
- ES6学习之环境配置
环境配置 一.建立工程目录 新建dist文件夹(用于存放转化的es5文件).新建src文件夹(用于存放es6文件),在该文件夹下建立index.js文件 二.编写index.html 在根目录下新建i ...