Be Careful
Time limit1sMemory limit1024 MB
Count the leaf fillings for each k from 0 to n so that the mex-propagated value at the root is exactly k, modulo 998244353.
- Level
Medium7 of 10
- Topics
- Tree, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
You are given a rooted tree with vertices, where the root is vertex . A vertex is a leaf if it is not the root vertex and its degree is exactly .

The figure corresponds to the sample tests, where the leaves are marked red.
Let be the minimal non-negative integer that is not present in . For example, , , .
Let be the number of leaves in the given tree. You will perform the following procedure:
- For every leaf vertex , write any integer from to the vertex .
- For every non-leaf vertex , the integer written in will be the of the integers written in all the sons of vertex .
For example, for the first tree in the figure, if you write to vertex and to vertex , then vertex gets , vertex gets , and vertex gets .
In total, there are ways to fill the tree. For every , count the ways to fill the tree so that the number written in vertex is exactly . Since the numbers can be huge, output them modulo .