Tree
Time limit3sMemory limit1024 MB
For each n up to N, count pairs of the two specified rooted trees whose leaf sets are complementary, modulo M.
- Level
Hard9 of 10
- Topics
- Combinatorics, Dynamic programming, Math
- Solved
- No attempts yet
Problem
We generate two rooted trees with vertices as follows.
The first tree is generated as follows:
- Vertex is the root of the tree.
- For every , choose one vertex from as the parent of .
The second tree is generated as follows:
- Vertex is the root of the tree.
- For every , choose one vertex from as the parent of .
A way of generating the trees is good if and only if every vertex that is a leaf in tree 1 is not a leaf in tree 2, and every vertex that is not a leaf in tree 1 is a leaf in tree 2. The root of each tree is not a leaf, regardless of the number of adjacent edges.
For every , calculate the number of good ways to generate the trees. Two ways are different if and only if there is a vertex such that the parent of is different in at least one of the two trees. Output the answer modulo .
Input
The first line of input contains two integers and (, ).
Output
Output lines: the answers for .