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 }