445B.md (1875B)
1 Source: https://codeforces.com/problemset/problem/445/B 2 3 B. DZY Loves Chemistry 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 DZY loves chemistry, and he enjoys mixing chemicals. 22 23 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. 24 25 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. 26 27 Find the maximum possible danger after pouring all the chemicals one by one in optimal order. 28 29 Input 30 31 The first line contains two space-separated integers *n* and *m* . 32 33 Each of the next *m* lines contains two space-separated integers *x**i* and *y**i* (1 ≤ *x**i* < *y**i* ≤ *n*). These integers mean that the chemical *x**i* will react with the chemical *y**i*. Each pair of chemicals will appear at most once in the input. 34 35 Consider all the chemicals numbered from 1 to *n* in some order. 36 37 Output 38 39 Print a single integer — the maximum possible danger. 40 41 Examples 42 43 Input 44 45 ``` 46 1 0 47 ``` 48 49 Output 50 51 ``` 52 1 53 ``` 54 55 Input 56 57 ``` 58 2 1 59 1 2 60 ``` 61 62 Output 63 64 ``` 65 2 66 ``` 67 68 Input 69 70 ``` 71 3 2 72 1 2 73 2 3 74 ``` 75 76 Output 77 78 ``` 79 4 80 ``` 81 82 Note 83 84 In the first sample, there's only one way to pour, and the danger won't increase. 85 86 In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2. 87 88 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).