DZY Loves Chemistry

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
Input
1 0
Output
1
Input
2 1
1 2
Output
2
Input
3 2
1 2
2 3
Output
4
Note

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

写题的时候估计脑袋被驴踢了,就是依次把化学物品倒入试管,如果有反应的危险值*2,如果没有反应的危险值就不变

 #include<iostream>
#include<cstdio>
#include<cmath> using namespace std; #define N 55 int f[N]; int found(int a)
{
if(f[a] != a)
f[a] = found(f[a]);
return f[a];
} int main()
{
int n, m, a, b; while(scanf("%d%d", &n, &m) != EOF)
{
for(int i = ; i <= n; i++)
f[i] = i;
int x = n; while(m--)
{
scanf("%d%d", &a, &b);
int na = found(a), nb = found(b);
f[na] = nb;
} for(int i = ; i <= n; i++)
{
if(f[i] == i) // 如果根节点是他自己,和别人没关系,放进去就不反应,就少乘一个2,有几颗树,就有几个根节点放进去的时候是不反应的
x--;
}
long long ans = pow(, x); printf("%lld\n", ans);
}
return ;
}

最新文章

  1. 人工智能AI-机器视觉CV-数据挖掘DM-机器学习ML-神经网络-[资料集合贴]
  2. linux下mnt目录作用
  3. Python virtualenv安装库报错SSL: CERTIFICATE_VERIFY_FAILED
  4. app工程构成
  5. java SE (java Standard Edition)
  6. JAVA面试题:69道Spring面试题和答案
  7. 对C语言中sizeof细节的三点分析
  8. CSS围住浮动元素的三种方法
  9. C#遍历获取枚举的值,名和属性
  10. 安装ArcGIS License 10.1 许可管理器 破解版 服务启动又失败的解决办法
  11. HDU 2209 翻纸牌游戏(DFS)
  12. 洛谷 P3379 【模板】最近公共祖先(LCA)
  13. html+css+jq随记
  14. linux中文件多行合并为一行的例子
  15. JS事件基础
  16. 使用request爬取拉钩网信息
  17. [iOS]图片高清度太高, 导致内存过大Crash
  18. hashMap 根据已有知识知道的
  19. vs2012更改默认开发环境
  20. 对HashMap的理解(二):高并发下的HashMap

热门文章

  1. mysql 8.X.X版本多个ip限制访问
  2. 网络流强化-POJ2516
  3. 微信小程序这一块(续)
  4. thymeleaf 下拉选框回显选中
  5. C++学习笔记(一)--基础
  6. css 绘制checkbox,radio
  7. python学习第三十天函数的形参,实参及函数文档
  8. C Sleepy Kaguya
  9. C#设计模式:桥接模式(Bridge Pattern)
  10. iview table列中根据不同的状态显示不同的颜色,显示图片