#P5818. [JSOI2011] 同分异构体计数

[JSOI2011] 同分异构体计数

Description

Antonio has recently become interested in organic chemistry, and he wants you to help him quickly compute the number of structural isomers of a certain type of hydrocarbon.

For convenience, we define the following:

  • Cycloalkane: A cycloalkane with nn carbon atoms can be represented as an undirected connected simple graph with nn vertices and nn edges (a base cycle plus outward trees). The degree of each vertex is at most 44.
  • M-cycloalkane: A cycloalkane in which at most mm vertices lie on the cycle. (Note that the cycle must contain at least 33 vertices, because between any two vertices there can be at most 11 edge.)
  • Isomorphism: Suppose structures AA and BB both have nn carbon atoms. AA and BB are isomorphic if and only if we can label every carbon atom in both AA and BB with numbers 1n1 \sim n such that for two carbon atoms labeled v1v_1 and v2v_2, there is an edge between them in AA if and only if there is an edge between them in BB. (In other words, the corresponding graphs of AA and BB are isomorphic.)

Now, given nn and mm, Antonio wants you to count how many pairwise non-isomorphic M-cycloalkanes with nn carbon atoms there are. Since this number may be very large, you only need to output it modulo pp (pp is a prime).

In this problem, we do not consider whether a structure can exist stably in chemistry, and we do not consider other types of isomerism.

Input Format

The input contains only one line with three integers nn, mm, and pp, separated by spaces.

Output Format

Output exactly one line: the number of pairwise non-isomorphic M-cycloalkanes with nn carbon atoms, modulo pp.

10 10 66103
475

Hint

Constraints

3n10003 \le n \le 1000, 3m503 \le m \le 50, mnm \le n, 104p2×10910^4 \le p \le 2 \times 10^9, and pp is guaranteed to be prime.

Translated by ChatGPT 5