#P4547. [THUWC 2017] 随机二分图
[THUWC 2017] 随机二分图
Description
Someone is playing a very magical game. In this game, there is a bipartite graph with vertices on the left and vertices on the right, and edges appear randomly according to certain rules.
To describe these rules, the edges are partitioned into several groups. Each edge either belongs to exactly one group, or to no group at all (such edges will never appear).
There are exactly the following three types of groups:
- Each such group contains exactly one edge, and that edge appears with probability .
- Each such group contains exactly two edges; the two edges either both appear with probability , or both do not appear with probability .
- Each such group contains exactly two edges; exactly one of the two appears, and each has probability of appearing.
Edge appearances from different groups are mutually independent.
Now that the grouping and types of edges are given, one wants to know the expected number of perfect matchings. Can you help her solve this problem?
Input Format
Read from standard input.
The first line contains two integers and , denoting the number of vertices on each side of the bipartite graph and the number of edge groups. We use (where ) to denote an edge whose left endpoint is the -th vertex on the left and whose right endpoint is the -th vertex on the right.
The next lines each describe one group. The first number denotes the group type, where means a one-edge group, means the first kind of two-edge group, and means the second kind of two-edge group. If , then the next two integers specify the single edge in the group. Otherwise, the next four integers specify that the two edges in the group are and . It is guaranteed that each edge appears at most once.
Output Format
Output to standard output.
Suppose the expected number of perfect matchings is . Output one line:
It can be seen that the above expression is an integer.
2 2
1 2 1 2 2
2 1 2 1 1
2
3 5
1 1 2 3 3
1 3 2 2 2
1 1 1 1 3
1 2 1 3 1
0 2 3
7
4 9
2 4 1 4 2
1 3 2 1 4
2 2 1 4 4
2 3 4 1 1
2 4 3 2 4
2 2 2 3 1
0 1 3
0 3 3
1 2 3 1 2
20
Hint
Definition Explanation.
If you are familiar with the definitions of perfect matching and expectation, you may skip this part.
For a bipartite graph with vertices on each side, a perfect matching is a matching consisting of edges with no shared endpoints.
Two perfect matchings are different if and only if they contain at least one different edge. The number of perfect matchings of a bipartite graph is defined as the number of pairwise distinct perfect matchings that can be found in this graph.
In this problem, edges appear randomly, so the number of perfect matchings is a random variable. The expectation of a (discrete) random variable is defined as the probability-weighted average of all possible values of , i.e.,
where denotes the set of all possible values of , and denotes the probability that takes the value .
Constraints.
- For of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For another of the testdata, only occurs.
- For another of the testdata, only occurs and , i.e., the graph is a complete graph.
- For another of the testdata, only or occurs.
- For another of the testdata, only or occurs.
- For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号