QOJ.ac

QOJ

実行時間制限: 3 s メモリ制限: 512 MB 満点: 100 難易度: [表示]

#2307. Tree

統計

Trees

Kelian is a girl who loves creating problems.

Although creating problems is a very interesting thing, turning them into a formal competition is not as fun: creating test data is always an exhausting task.

In ZJOI2018 Day 1, Kelian created a very interesting problem related to trees. She plans to use a common method to randomly generate a rooted tree with $n$ nodes:

  • Node 1 is the root of the tree.
  • For $i \in [2, n]$, independently and uniformly choose a node from $[1, i)$ as the parent of $i$.

Kelian does not really want to consider whether the randomly generated data can "break" brute-force solutions, as "hacking" is part of the OI competition. What Kelian cares about is the discriminative power of the problem and whether all possible scores appear. Therefore, Kelian hopes that the trees in any two test cases are distinct: this way, it is possible that an incorrect program might only pass one of them.

Therefore, Kelian wants to calculate the probability that $k$ rooted trees with $n$ nodes, $T_1$ to $T_k$, independently generated using the method above, are all pairwise isomorphic.

Two rooted trees $T_1$ and $T_2$ with $n$ nodes are isomorphic if and only if there exists a permutation $p$ of length $n$ such that $p_1 = 1$, and for all $i \in [2, n]$, if the parent of $i$ in $T_1$ is $f$, then the parent of $p_i$ in $T_2$ is $p_f$.

Input

The first line contains three integers $n, k, p$, representing the number of nodes, the number of trees, and the modulus. It is guaranteed that $10^8 \le p \le 10^9$ and $p$ is a prime number.

Output

Output a single integer representing the answer modulo $p$. That is, if the simplest fractional representation of the answer is $\frac{a}{b}$, output $a \times b^{-1} \pmod p$.

Examples

Input 1

2 2 998244353

Output 1

1

Input 2

3 2 998244353

Output 2

499122177

Input 3

4 2 998244353

Output 3

332748118

Input 4

10 2 998244353

Output 4

113919852

Input 5

50 233 998244353

Output 5

634280054

Note

There are five different sets of data in the examples, so the input format is slightly different. In the actual test data, the input consists of only one line.

In the first data set, the generated tree is unique, so the two generated trees must be identical.

In the second data set, there are only two possible trees that can be generated, and they are not isomorphic. Therefore, the probability that the two generated trees are isomorphic is $\frac{1}{2}$, which is $499122177$ modulo $998244353$.

In the third data set, there are 6 possible trees that can be generated, as shown in the figure below. Among them, the second, third, and fourth trees (the three in the middle of the first row) are isomorphic, while the others are pairwise non-isomorphic. Therefore, the probability that the two generated trees are isomorphic is $\frac{1}{3}$, which is $332748118$ modulo $998244353$.

Constraints

Test Case $n$ $k$ Test Case $n$ $k$
1 $\le 5$ $=2$ 6 $\le 50$ $\le 10^9$
2 $\le 10$ 7 $\le 200$
3 $\le 20$ 8 $\le 500$
4 $\le 50$ 9 $\le 1000$
5 10 $\le 2000$

For 100% of the data, it is guaranteed that $p$ is a prime number and $10^8 \le p \le 10^9$.

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.