#P4500. [ZJOI2018] 树

[ZJOI2018] 树

Description

Jiutiao Kelian (pinyin) is a girl who loves to write problems.

Although writing problems itself is very interesting, turning a problem into an official contest task is not so fun: generating testdata is always exhausting.

In ZJOI 2018 Day 1, Kelian set a very interesting problem about trees. She plans to use a common method to randomly generate a rooted tree with nn nodes:

  • Node 11 is the root of the tree.
  • For i[2,n]i \in [2, n], independently and uniformly at random pick a node from [1,i)[1, i) as the parent of ii.

Kelian does not really want to think about whether such randomly generated testdata can defeat brute force, since hacking around is also part of OI contests.

What Kelian cares about more is the problem's discriminative power, and whether all possible scores appear. Therefore, she hopes that the trees in any two test points are different, so that an incorrect program might pass only one of them.

Thus, Kelian wants to compute the probability that, by independently generating kk rooted trees with nn nodes T1T_1 to TkT_k using the method above, they are pairwise isomorphic.

Two rooted trees T1T_1 and T2T_2 with nn nodes are isomorphic if and only if there exists a permutation pp of length nn, satisfying p1=1p_1 = 1, and for all i[2,n]i \in [2, n], if the parent of ii in T1T_1 is ff, then the parent of pip_i in T2T_2 is pfp_f.

Input Format

The first line contains three integers n,k,pn, k, p, denoting the number of nodes, the number of trees, and the modulus. It is guaranteed that 108p10910^8 \leq p \leq 10^9 and pp is prime.

Output Format

Output a single integer, the answer modulo pp. That is, if the answer in lowest terms is ab\frac{a}{b}, output a×b1modpa \times b ^{-1} \bmod p.

2 2 998244353

1
3 2 998244353
499122177
4 2 998244353
332748118
10 2 998244353
113919852
50 233 998244353
634280054

Hint

Sample Explanation

In the first sample, the generated tree is unique, so the two generated trees are necessarily identical.

In the second sample, there are only two possible generated trees, and they are non-isomorphic. Therefore, the probability that the two generated trees are isomorphic is 12\frac{1}{2}, which is 499122177499122177 modulo 998244353998244353.

In the third sample, there are 66 possible generated trees, as shown below. Among them, the second, third, and fourth (the middle three in the first row) are isomorphic, and the remaining ones are pairwise non-isomorphic. Therefore, the probability that the two generated trees are isomorphic is 13\frac{1}{3}, which is 332748118332748118 modulo 998244353998244353.

Constraints

测试点 nn kk 测试点 nn kk
1 5\le 5 =2=2 6 50\le 50 109\le 10^9
2 10\le 10 7 200\le 200
3 20\le 20 8 500\le 500
4 50\le 50 9 1000\le 1000
5 10 2000\le 2000

For 100%100\% of the testdata, it is guaranteed that pp is prime and 108p10910^8 \le p \le 10^9.

Thanks to @Xeonacid for providing the statement.

Translated by ChatGPT 5