官方题解
Instead of counting sum(the minimum vertex cover)^m, we can use the ordered pair technique. This
insight leads to solving a different problem: select a set of vertices of upto m size, in how many different
subsets of vertices of the tree these vertices are guaranteed to be selected as the minimum vertex cover.
Then we count the sum over the sizes of all sets of vertices.
What we really want is given a set of vertices from the minimum vertex cover, can we get back the original
sub-tree. That way we can generate all possible subtrees and in turn count the subset of vertices that will
contain this given set as minimum vertex cover. This turns out to be difficult to do, unless you consider
the maximum matching instead of minimum vertex cover and always assign the vertex closer to the root
(of the whole tree) as the cover vertex.
This approach can lead to a bottom up sibling dp solution. From each node we need to calculate 2 things,
the number of ways to select k ≤ m maximum matching with the subtree below the vertex and the sibling
vertices with the current vertices matching with one of the children or the current vertices becoming
available for matching with the parent. Merging the count from the children and the siblings requires
convolution, thankfully with some small optimization we can avoid doing fft.
This dp calculation is a little tricky, as you need to think about what happens in a lot of situations. Like,
whether to cut off the edge from the parent and remove the subtree rooted at the current vertex, when
the current vertex is matched with a child, do we count it as part of the k set or we don’t, is the vertex
included in the subset or not.
At the end, you will have the count of selecting exactly k different vertices and the number of subsets
where they will be guaranteed to be a part of the minimum vertex cover, from there we can calculate the
number of ordered lists of size m from k vertices (from the ordered pair technique). The sum of them is
the result.
To avoid doing fft, we can do this trick: instead of multiplying m × m, we avoid the suffix with 0s. So,
we find the last non-zero position of both arrays, say non_zero_a and non_zero_b, so we multiply two
arrays of size non_zero_a × non_zero_b. We can also stop multiplying if the multiplication will be
added to any position beyond m.