QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 1024 MB 満点: 100

#6653. Yin-Yang Formation

統計

There is a graph with $n$ white nodes and $m$ black nodes. All white nodes are distinct from each other, and all black nodes are distinct from each other. Each node has exactly one outgoing edge, and the target of each edge can be chosen from any of the $n + m$ nodes. There are a total of $(n + m)^{n+m}$ possible configurations, and each configuration forms a directed functional graph (a collection of components, each consisting of a cycle with some trees rooted on the cycle nodes).

A configuration is considered "good" if and only if it satisfies the following conditions: Every black node points to a white node. The product of the number of black nodes and the number of white nodes in each cycle is even.

You need to find the number of good configurations, modulo $P$.

Input

The input consists of a single line containing three integers $n, m, P$, as described above.

Output

Output a single integer representing the answer.

Examples

Input 1

2 1 1000000

Output 1

12

Note 1

Considering the constraint that every black node must point to a white node, there are $3 \times 3 \times 2 = 18$ total configurations. Among these, configurations where one black node and one white node form a cycle are invalid. The number of ways to choose one white node and one black node to form a cycle is 2, and the remaining white node has 3 possible choices for its outgoing edge, so there are $2 \times 3 = 6$ invalid configurations. The answer is $18 - 6 = 12$.

Input 2

8 8 8888888

Output 2

2973992

Input 3

1000 1000 123456789

Output 3

55105667

Constraints

For all test cases, $1 \le n, m \le 2000$, $1 \le P \le 10^9$.

Note

You may need to pay attention to the impact of constants on the efficiency of your algorithm.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#856EditorialOpen题解alpha10222026-01-28 02:26:58View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.