#P5547. [BJ United Round #3] 三色树

    ID: 6301 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP数学北京O2优化组合数学

[BJ United Round #3] 三色树

Problem Description

Please count the number of unlabeled unrooted trees with nn nodes that satisfy the following requirements:

  • Each node has one of three colors: red, blue, or yellow.
  • The degree of a red node is at most 44, and the degrees of blue and yellow nodes are both at most 33.
  • Yellow nodes cannot be adjacent.

Note that the meaning of an unlabeled unrooted tree is: if two trees can be made identical by renumbering the nodes so that the corresponding nodes have the same colors and the corresponding edges match, then they are considered the same tree.

The answer should be taken modulo the prime number pp given in the input.

Input Format

Two positive integers n,pn,p, with the meanings as described above.

Output Format

One integer, representing the number of valid trees modulo pp.

2 998244353
5
3 998244353
15
20 998244353
578067492

Hint

For 100%100\% of the testdata, it is guaranteed that: 1n30001\le n \le 3000. 9×108p1.01×1099\times 10^8 \le p \le 1.01 \times 10^9. It is guaranteed that pp is prime.

By: EntropyIncreaser

Translated by ChatGPT 5