Codeforces round #254 (Div. 2) B. dzy loves Chemistry (and query set)

Source: Internet
Author: User

Question Link

I didn't make the question last night. I still understood the question wrong when I first read the question. I thought about the order in which I thought, and I thought about it,

It is also misled by the example below.

Question:

There are 1-N kinds of chemicals, a total of M can respond to the reagent, in different order to drop 1-N kinds of reagents into the test tube, if the agent is being dropped into

The number of hazards * 2, otherwise remain unchanged. Ask the maximum risk factor at the end.

Analysis: in fact, this question does not need to consider the order of import. It only needs to be segmented. The result is the power of 1 and 2 of the number of elements in each subset.

 1 #include <iostream> 2 #include <cstring> 3 #include <queue> 4 #include <cmath> 5 #include <cstdio> 6 #include <algorithm> 7 #define LL long long 8 using namespace std; 9 const int maxn = 50 + 10;10 int n, m, bin[maxn], f[maxn], cou;11 int find(int x)12 {13     return bin[x]==x?x:(bin[x]=find(bin[x]));14 }15 void merge(int x, int y)16 {17     int fx = find(x);18     int fy = find(y);19     if(fx != fy)20     {21         bin[fx] = fy;22         cou ++;23     }24 }25 int main()26 {27     int i, x, y;28     LL ans;29     while(~scanf("%d%d", &n, &m))30     {31         cou = 0;32         for(i = 1; i <= n; i++)33         bin[i] = i;34         while(m--)35         {36             cin>>x>>y;37             merge(x, y);38         }39         ans = pow(2, cou);40         cout<<ans<<endl;41     }42     return 0;43 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.