DZY Loves Chemistry

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

DZY loves chemistry, and he enjoys mixing chemicals.

DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.

Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours a chemical, if there are already one or more chemicals in the test tube that can react with it, the danger of the test tube will be multiplied by 2. Otherwise the danger remains as it is.

Find the maximum possible danger after pouring all the chemicals one by one in optimal order.

Input

The first line contains two space-separated integers n and m.

Each of the next m lines contains two space-separated integers xi and yi(1 ≤ xi < yi ≤ n). These integers mean that the chemical xi will react with the chemical yi. Each pair of chemicals will appear at most once in the input.

Consider all the chemicals numbered from 1 to n in some order.

Output

Print a single integer — the maximum possible danger.

Sample Input

Input
1 0
Output
1
Input
2 1
1 2
Output
2
Input
3 2
1 2
2 3
Output
4

Hint

In the first sample, there's only one way to pour, and the danger won't increase.

In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2.

In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that is the numbers of the chemicals in order of pouring).

 #include<stdio.h>

 int pre[];

 int Find(int x)
{
int r=x;
while(r!=pre[r])
r=pre[r];
int i=x,j;
while(pre[i]!=r)
{
j=pre[i];
pre[i]=r;
i=j;
}
return r;
} void join(int x,int y)
{
int fx=Find(x),fy=Find(y);
if(fx!=fy)
pre[fy]=fx;
} int main()
{
int n,m,i,j,x,y;
while(scanf("%d %d",&n,&m)!=EOF)
{
for(i=;i<=n;i++)
pre[i]=i;
for(i=;i<=m;i++)
{
scanf("%d %d",&x,&y);
join(x,y);
}
int t[]={},k=;
for(i=;i<=n;i++)
t[Find(i)]=;
for(i=;i<=n;i++)
if(t[i]==)
k++;
long long ans=;
for(i=;i<=n-k;i++)
ans=ans*;
printf("%I64d\n",ans);
}
return ;
}

CodeForces 445B DZY Loves Chemistry的更多相关文章

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

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

  2. codeforces 445B. DZY Loves Chemistry 解题报告

    题目链接:http://codeforces.com/problemset/problem/445/B 题目意思:给出 n 种chemicals,当中有 m 对可以发生反应.我们用danger来评估这 ...

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

    题意: 有N种药剂编号 1 ~ N,然后有M种反应关系,这里有一个试管,开始时危险系数为 1,每当放入的药剂和瓶子里面的药剂发生反应时危险系数会乘以2,否则就不变,给出N个药剂和M种反应关系,求最大的 ...

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

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

  5. CodeForces - 445B - DZY Loves Chemistry-转化问题

    传送门:http://codeforces.com/problemset/problem/445/B 参考:https://blog.csdn.net/littlewhite520/article/d ...

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

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

  8. DZY Loves Chemistry 分类: CF 比赛 图论 2015-08-08 15:51 3人阅读 评论(0) 收藏

    DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces 444C DZY Loves Colors(线段树)

    题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...

随机推荐

  1. 夺命雷公狗ThinkPHP项目之----企业网站27之网站前台单页的完成(从百度编辑器里面取出文章数据)

    我们的单页面里主要是为了可以取出文章分类表的栏目内容,废话先不说, 我们的实现要点: 1...获取get过来的栏目cate_id 2...然后用条件查询栏目表 <?php namespace H ...

  2. scrum站立会议------10.20

    小组名称:nice! 小组成员:李权 于淼 杨柳 刘芳芳 项目内容:约跑app(约吧--暂定) 1.任务进度 2.燃尽图

  3. word - 如何让 图片任意移动

    选中图片, 设置图片的自动换行  为四周环绕型

  4. 【cruch bang】中切换成左手鼠标

    在“右键”菜单->settings->Edit autostart启动的geany编辑器中,最后加内容: xmodmap -e 'pointer = 3 2 1'

  5. 五、Java基础---------if else、switch总结

    在前几篇博客中主要是以笔者遇到的一些典型的题目为例子而展开的讨论,接下来几篇将是以知识点的结构进行讲述.本文主要是讲述if ()else .if() else if().switch() case 的 ...

  6. SSAS更改默认端口号,使用非默认端口号的时候Olap连接字符串的格式

    Sql server的Analysis Service服务默认使用的是2382或2383端口,但是实际上我们可以通过配置文件手动更改SSAS使用其它端口号. 修改SSAS使用端口号的方法如下,找到你的 ...

  7. bug管理规范

    资源来自:http://wenku.baidu.com/view/ae55b3b565ce05087632132b.html

  8. PL/SQL快捷键

    F8 执行所选中的SQL语句 当光标在sql语句末尾/开头 时 按Shift  Home /Shift  End 选中该语句

  9. innodb的锁时间

    观察innodb的锁时间,需要关注: mysqladmin extended-status -r -i 1 -uroot | grep "Innodb_row_lock_time" ...

  10. Linux内核抢占与中断返回【转】

    转自:http://blog.csdn.net/tommy_wxie/article/details/7425728 版权声明:本文为博主原创文章,未经博主允许不得转载. [html] view pl ...