题意:给出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【并查集】的更多相关文章

  1. UOJ_14_【UER #1】DZY Loves Graph_并查集

    UOJ_14_[UER #1]DZY Loves Graph_并查集 题面:http://uoj.ac/problem/14 考虑只有前两个操作怎么做. 每次删除一定是从后往前删,并且被删的边如果不是 ...

  2. UOJ14 DZY Loves Graph 并查集

    传送门 题意:给出一张$N$个点,最开始没有边的图,$M$次操作,操作为加入边(边权为当前的操作编号).删除前$K$大边.撤销前一次操作,每一次操作后询问最小生成树边权和.$N \leq 3 \tim ...

  3. cf444E. DZY Loves Planting(并查集)

    题意 题目链接 Sol 神仙题啊Orzzzzzz 考场上的时候直接把树扔了对着式子想,想1h都没得到啥有用的结论. 然后cf正解居然是网络流??出给NOIP模拟赛T1???¥%--&((--% ...

  4. Codeforces 445 A DZY Loves Chessboard【DFS】

    题意:给出n*m的棋盘,在‘.’处放上B或者W,最后要求所有的B和W都不相邻 先把棋盘的点转化成‘B’,再搜,如果它的四周存在‘B’,则将它变成'W' 一直挂在第五个数据的原因是,没有dfs(nx,n ...

  5. CodeForces 445B DZY Loves Chemistry

    DZY Loves Chemistry Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  6. CodeForces 445B. DZY Loves Chemistry(并查集)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://codeforces.com/problemset/prob ...

  7. CF 445B DZY Loves Chemistry(并查集)

    题目链接: 传送门 DZY Loves Chemistry time limit per test:1 second     memory limit per test:256 megabytes D ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 蓝桥杯 - 带分数 (DFS)

      历届试题 带分数   时间限制:1.0s   内存限制:256.0MB        问题描写叙述 100 能够表示为带分数的形式:100 = 3 + 69258 / 714. 还能够表示为:10 ...

  2. JUnit4.8.2源码分析-4 RunNotifier与RunListener

    JUnit4运行过程中,org.junit.runner.notification. RunListener和RunNotifier运用了观察者模式. 1.观察者 观察者Observer/Listen ...

  3. Avalon.js 实现列表

    <table border="0" cellpadding="0" cellspacing="0" class="tab1& ...

  4. 为什么在3ds Max 按系统默认的快捷键AIT+W 视口最大化切换没反应?

    经常使用3ds Max快捷键做效果图可谓是提高作图速度的毕竟之路,做效果图的朋友或许会遇到最大化视口显示失灵的问题,max默认快捷键为Alt+W,这里我不建议大家更改max的默认快捷键,当然Max也提 ...

  5. iOS开发——Block使用小结

    Block语法看上去好像很特别,但它实际上是作为极普通的C语言源代码处理的.Block的实质,就是Objective-C的对象. 1.Block的语法 ^ 返回值类型 参数列表 表达式 可省略返回值类 ...

  6. 15条JavaScript最佳实践【转】

    本文档整理大部分公认的.或者少有争议的JavaScript良好书写规范(Best Practice).一些显而易见的常识就不再论述(比如要用对象支持识别判断,而不是浏览器识别判断:比如不要嵌套太深). ...

  7. json对象与其字符串之间的转换

    在数据传输过程中,json是以文本,即字符串的形式传递的,而JS操作的是JSON对象,所以,JSON对象和JSON字符串之间的相互转换是关键.例如: JSON字符串:var str1 = '{ &qu ...

  8. 安装 glusterfs yum源报错

    yum install glusterfs-server yum 一直报错 把/etc/yum.repos.d 备份 删除了所有文件,从测试机192..168.59.128上同步过来 一直报错 已加载 ...

  9. 关闭linux终端进程

    [root@linux-node1 ~]# w 22:16:45 up 24 days, 24 min, 2 users, load average: 0.28, 0.17, 0.15 USER TT ...

  10. How to enable wire logging for a java HttpURLConnection traffic?

    https://stackoverflow.com/questions/1445919/how-to-enable-wire-logging-for-a-java-httpurlconnection- ...