#abc321g. G - Electric Circuit
G - Electric Circuit
Score : points
问题描述
你正在使用 个编号为 到 的部件和 根电缆创建一个电路。这些部件共有 个红色接头和 个蓝色接头,其中第 个红色接头连接到部件 ,第 个蓝色接头连接到部件 。每根电缆连接一个红色接头和一个蓝色接头,特别地,允许将同一个部件上的两个接头连接起来。不允许在一个接头上连接两根或更多的电缆。因此,总共有 种不同的方式来连接这 根电缆(不区分电缆之间)。
令 表示当把这个电路看作是一个由部件作为顶点、电缆作为边的图时的连通分量数量。在随机从 种方式中选择一种来连接 根电缆时,求 的期望值对 取模的结果。
寻找一个对 取模后的期望值是什么意思?可以证明所求的期望值始终是一个有理数。此外,在本题的约束条件下,可以证明当该值表示为两个互质整数 和 的形式 时,存在恰好一个整数 满足 以及 。找出这个 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are creating an electrical circuit using parts numbered to and cables. These parts have a total of red terminals and blue terminals, with the -th red terminal attached to part and the -th blue terminal attached to part . Each cable connects one red terminal and one blue terminal. In particular, it is allowed to connect two terminals attached to the same part. You cannot connect two or more cables to a terminal. Therefore, there are ways in total to connect the cables (the cables are not distinguished from each other).
Let be the number of connected components when seeing this circuit as a graph with parts as vertices and cables as edges. Find the expected value, modulo , of when randomly choosing the way to connect the cables out of the ways.
What does it mean to find an expected value modulo ? It can be proved that the sought expected value is always a rational number. Also, under the constraints of this problem, it can be proved that when this value is expressed as using two coprime integers and , there is exactly one integer that satisfies and . Find this .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the expected value of , modulo .
Sample Input 1
3 2
1 2
3 2
Sample Output 1
499122178
Let denote the action of connecting the -th red terminal and the -th blue terminal with a cable.
- For : There will be two connected components, and , so .
- For : The whole graph constitutes one connected component, so .
Thus, the expected value of is .
Sample Input 2
17 5
1 1 1 1 1
1 1 1 1 1
Sample Output 2
17
no matter how you connect the cables.
Sample Input 3
8 10
2 4 7 1 7 6 1 4 8 1
5 1 5 2 5 8 4 6 1 3
Sample Output 3
608849831
update @ 2024/3/10 01:41:36