Subtrees
Time limit2sMemory limit1024 MB
Given a tree with n vertices, count the ways to choose k vertex-disjoint subtrees for each k from 1 to n, modulo 10^9.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Tree, Combinatorics
- Solved
- No attempts yet
Problem
A tree is a connected undirected graph without cycles. A subtree of a tree is a connected subgraph of .
The number of subtrees depends on the structure of the tree. For example, a path of vertices has subtrees, and a star (one central vertex connected to the other vertices) has subtrees.
Similarly, the number of ways to choose two vertex-disjoint subtrees, three vertex-disjoint subtrees, and so on also depends on the structure of the tree.
Regardless of the structure, there are ways to choose vertex-disjoint subtrees, and exactly one way to choose vertex-disjoint subtrees (just isolated vertices).
Given a tree with vertices, print for each from 1 to the number of ways to choose vertex-disjoint subtrees of the tree.
Input
The first line contains (). The next lines describe the edges of the tree.
Output
Print integers: for each from 1 to , the number of ways to choose vertex-disjoint subtrees of the given tree. Print each number modulo .