#P6653. Grafting Tree Species
Grafting Tree Species
Grafting Tree Species
Ysuperman has bought a batch of identical trees which are unrooted. To spice things up, Ysuperman decides to perform a "grafting" operation on one of these trees. The grafting operation is defined as follows:
- A leaf node of a tree is defined as a node with degree 1.
- A grafting operation means attaching a new leaf node to an existing node of the unrooted tree. Two grafting schemes are considered different if and only if the new leaf is attached to different existing nodes.
Every tree has a property called its species. The species of a tree is defined as the multiset of each node's largest subtree size. For any node in a tree, its largest subtree size is the maximum number of nodes in any connected component after that node is removed.
Two trees have different species if and only if their multisets of largest subtree sizes (one value per node) are different. For example, consider the following cases:
- Tree A: the multiset is \(\{2,2,3,3\}\).
- Tree B: the multiset is \(\{2,2,3,3\}\) (same as A).
- Tree C: the multiset is \(\{1,3,3,3\}\) (different from A and B).
Ysuperman wants to know that by performing one grafting operation on the given tree, how many different species can be obtained and how many different grafting schemes yield each species. You are to output, in ascending order, the number of grafting schemes for each species.
Note: The input tree is an unrooted tree. A grafting scheme is determined solely by the node to which the new leaf is attached.
inputFormat
The first line contains an integer n (the number of nodes in the original tree).
Each of the next n-1 lines contains two integers u and v (1 ≤ u, v ≤ n) indicating there is an edge between nodes u and v in the tree.
It is guaranteed that the given graph is a tree.
outputFormat
Output a single line containing the counts of grafting methods for each distinct species (obtained after performing the grafting operation), sorted in ascending order. Separate the numbers by a space.
sample
1
1