#P5547. [BJ United Round #3] 三色树
[BJ United Round #3] 三色树
Problem Description
Please count the number of unlabeled unrooted trees with 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 , and the degrees of blue and yellow nodes are both at most .
- 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 given in the input.
Input Format
Two positive integers , with the meanings as described above.
Output Format
One integer, representing the number of valid trees modulo .
2 998244353
5
3 998244353
15
20 998244353
578067492
Hint
For of the testdata, it is guaranteed that: . . It is guaranteed that is prime.
By: EntropyIncreaser
Translated by ChatGPT 5