题意:给出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. Visual C++文件后缀名释义

    [1] .APS:存放二进制资源的资源辅助中间文件(可加快资源装载速度). [2] .BMP:位图资源文件. [3] .BSC:浏览信息文件.由浏览信息维护工具(BSCMAKE)从原始浏览信息文件(. ...

  2. QT中|Qt::Tool类型窗口自动退出消息循环问题解决(setQuitOnLastWindowClosed必须设置为false,最后一个窗口不显示的时候,程序会退出消息循环)

    为application 设置setQuitOnLastWindowClosed属性,确实为true: 将其显示为false; 退出该应该程序不能调用QDialog的close消息槽,只能调用qApp ...

  3. caffe环境配置

    参考:http://blog.csdn.net/enjoyyl/article/details/47397505 http://blog.csdn.net/baobei0112/article/det ...

  4. CentOS7设置中文输入法

    转自:https://i.cnblogs.com/EditPosts.aspx?postid=8327755&update=1 CentOS7设置中文输入法 安装CentOS7之后,鼓捣了半天 ...

  5. Linux进程精讲

    进程相关概念 程序和进程 程序,是指编译好的二进制文件,在磁盘上,不占用系统资源(cpu.内存.打开的文件.设备.锁....) 进程,是一个抽象的概念,与操作系统原理联系紧密.进程是活跃的程序,占用系 ...

  6. 133.throw机制 抛出类类型

    #include <iostream> using namespace std; //try尝试执行,抛出throw,throw之后语句不再执行 //catch处理throw的异常 voi ...

  7. sql/plus无法显示数据库问题

    登录PL/SQL Developer 这里省略Oracle数据库和PL/SQL Developer的安装步骤,注意在安装PL/SQL Developer软件时,不要安装在Program Files ( ...

  8. js中es5 使用call方法继承实现 1.0

    function Parent(name){ this.name = name; this.showMess = function(){ return this.name; } } Parent.pr ...

  9. windows2008 虚拟机64位的操作系统安装32位的应用程序

    64位的操作系统安装32位的应用程序: 安装成功但是使用有问题 报错: 最终解决: 在一台物理机的win7上面安装该软件. 然后把安装好的文件全部拷贝到win2008虚拟机上面 启动,使用 多ok了! ...

  10. iF.svnadmin 安装遇到的坑

    iF.svnadmin 官网:http://svnadmin.insanefactory.com/ 安装配置iF.svnadmin : http://blog.linhere.com/archives ...