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 ;
}

DZY Loves Chemistry的更多相关文章

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

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

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

  3. CodeForces 445B DZY Loves Chemistry

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

  4. cf445B DZY Loves Chemistry

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

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

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

  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. Codeforces Round #254 (Div. 2) B. DZY Loves Chemistry (并查集)

    题目链接 昨天晚上没有做出来,刚看题目的时候还把题意理解错了,当时想着以什么样的顺序倒,想着就饶进去了, 也被题目下面的示例分析给误导了. 题意: 有1-n种化学药剂  总共有m对试剂能反应,按不同的 ...

  9. Codeforces Round #254 (Div. 2) DZY Loves Chemistry【并查集基础】

    一开始不知道题意是啥意思,迟放进去反应和后放进去反应有什么区别 对于第三组数据不是很懂,为啥312,132的组合是不行的 后来发现这是一道考察并查集的题目 QAQ 怒贴代码: #include < ...

随机推荐

  1. MySQL replace into 与insert into

    https://blog.csdn.net/helloxiaozhe/article/details/77427266 使用replace带来的问题 1.Replace into 操作在唯一键重复情况 ...

  2. 编程语言-Python-GUI

    PyQt5 import sys from PyQt5 import QtWidgets,QtCore app = QtWidgets.QApplication(sys.argv) widget = ...

  3. Nginx 介绍配置

    nginx的功能和优缺点 nginx是一种服务器软件,将程序放在nginx服务器上,将程序发布出去,nginx是一种高性能的Http和反向代理服务器,同时也是一个代理邮件服务器,也可以实现负载均衡. ...

  4. jsp(java server page)

    jsp的组成元素; 1, 指令 page指令 <%@ page ..........%> language---当前页面使用的语言:java import---当前页面引入的类库, 默认是 ...

  5. PowerShell - Invoke VBA function

    $xl = new-object -comobject Excel.Application $source_wb = $xl.workbooks.open($source) $xl.visible=$ ...

  6. [LOJ3123] CTSC2019重复

    Description 给定一个⻓为 n 的字符串 s , 问有多少个⻓为 m 的字符串 t 满足: 将 t 无限重复后,可以从中截出一个⻓度为 n 且字典序比 s 小的串. m ≤ 2000 n ≤ ...

  7. [Bzoj1731]排队布局

    洛谷上的翻译是真的哲学♂♂♂ 非常van的题目传送门♂♂♂ 个人认为这题充其量也就是个蓝(nan)题,首先处理-1的情况,-1的情况是不等式组无解,按照差分约束的规则,无解说明出现了负环,先跑一遍以0 ...

  8. P2639 [USACO09OCT]Bessie的体重问题Bessie's Weight

    题目传送门 这题和01背包最大的区别在于它没有价值,所以我们可以人工给它赋一个价值,由于要求体积最大,把价值赋成体积即可.顺带一提,这题数据范围很大,二维会MLE,要压缩成一维才可以AC 下面给出参考 ...

  9. python-批量解压zip、rar文件

    这是一个用python写解压大量zip脚本的说明,本人新手一个,希望能对各位有所启发. GitHub:https://github.com/lgf133214/Windows-python3- 首先要 ...

  10. D Dandan's lunch

    链接:https://ac.nowcoder.com/acm/contest/338/D来源:牛客网 题目描述 As everyone knows, there are now n people pa ...