Under construction

Still being built. Things may change

Be Careful

Time limit1sMemory limit1024 MB

Summary
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 nn vertices, where the root is vertex 11. A vertex is a leaf if it is not the root vertex and its degree is exactly 11.

The figure corresponds to the sample tests, where the leaves are marked red.

Let mex⁡(S)\operatorname{mex}(S) be the minimal non-negative integer that is not present in SS. For example, mex⁡{0,1,3,4}=2\operatorname{mex}\{0, 1, 3, 4\} = 2, mex⁡{2,3}=0\operatorname{mex}\{2, 3\} = 0, mex⁡∅=0\operatorname{mex}\varnothing = 0.

Let mm be the number of leaves in the given tree. You will perform the following procedure:

  1. For every leaf vertex uu, write any integer from {0,1,2,…,n}\{0, 1, 2, \ldots, n\} to the vertex uu.
  2. For every non-leaf vertex uu, the integer written in uu will be the mex⁡\operatorname{mex} of the integers written in all the sons of vertex uu.

For example, for the first tree in the figure, if you write 00 to vertex 44 and 33 to vertex 55, then vertex 22 gets mex⁡{0}=1\operatorname{mex}\{0\} = 1, vertex 33 gets mex⁡{3}=0\operatorname{mex}\{3\} = 0, and vertex 11 gets mex⁡{1,0}=2\operatorname{mex}\{1, 0\} = 2.

In total, there are (n+1)m(n+1)^m ways to fill the tree. For every k∈{0,1,2,…,n}k \in \{0, 1, 2, \ldots, n\}, count the ways to fill the tree so that the number written in vertex 11 is exactly kk. Since the numbers can be huge, output them modulo 998 244 353998\,244\,353.

Examples3

  1. Example 1

    Input
    5
    1 2
    1 3
    2 4
    2 5
    
    Expected output
    55
    127
    34
    0
    0
    0
    
  2. Example 2

    Input
    8
    1 2
    1 3
    1 4
    1 5
    1 6
    6 7
    6 8
    
    Expected output
    69632
    265534
    133905
    47790
    12636
    1944
    0
    0
    0
    
  3. Example 3

    Input
    3
    1 2
    2 3
    
    Expected output
    1
    3
    0
    0