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 ...
随机推荐
- bzoj3295: [Cqoi2011]动态逆序对(cdq分治+树状数组)
3295: [Cqoi2011]动态逆序对 题目:传送门 题解: 刚学完cdq分治,想起来之前有一道是树套树的题目可以用cdq分治来做...尝试一波 还是太弱了...想到了要做两次cdq...然后伏地 ...
- js中cookie的使用 以及缺点
什么是Cookie Cookie意为“甜饼”,是由W3C组织提出,最早由Netscape社区发展的一种机制.目前Cookie已经成为标准,所有的主流浏览器如IE.Netscape.Firefox. ...
- 修改host文件浏览国外网站
公司电脑网络没法进github没办法工作需要只能FQ了. 方法1:用VPN 但是地要钱呐,没钱只能放弃了,不过每天试用还是可以的 方法2:改电脑host,文件中每条数据前面的#代表注释.把要访问的地址 ...
- 【原创】rman备份出现ORA-19625
[oracle@sunny stage]$ rman target / Recovery Manager: Release 10.2.0.1.0 - Production on Sun Mar 18 ...
- jq不懂的地方
在循环列表中,获取input标签的值,不能用id获取,用class获取值,通过父级属性找到class,this 指当前点击的位置var UID = $(this).parents("tr&q ...
- php报错权限设置
<?php //禁用错误报告 error_reporting(0); //报告运行时错误 error_reporting(E_ERROR | E_WARNING | E_PARSE); //报告 ...
- seq去除重复数据
DELETE FROM temp_fjh_2 a WHERE a.rowid!=(SELECT MAX(b.rowid) FROM temp_fjh_2 b WHERE a.a=b.a); 表名和列名 ...
- 创建一个 Django 项目
一. 创建项目 其中: 确认项目是否创建成功: 在 manage.py 目录上运行 python manage.py runserver server 启动后,在浏览器访问 http://127.0. ...
- tinymce原装插件源码分析(四)-fullscreen
fullscreen 作为一款文本编辑器,全屏功能是非常有必要的.在插件中主要是修改一些css style和触发resize事件. style问题(反例): 见github源码:https://git ...
- jQuery第一课 加载页面弹出一个对话框
<script type="text/javascript"> $(document).ready(function(){ alert("欢迎收看:" ...