#P6591. [YsOI2020] 植树
[YsOI2020] 植树
Background
In response to the call, Ysuperman decides to plant trees in a kindergarten.
Problem Description
Ysuperman has an unrooted tree with nodes. If you do not know what a tree is, they are happy to tell you that a tree is an undirected connected graph without cycles.
Since the tree is unrooted, there is no way to “plant” it. After studying gardening for a long time, Ysuperman finds that for a node to be able to serve as the root, it must be very balanced. This means that when it is chosen as the root, among the nodes directly connected to it, the sizes of their subtrees are all the same.
As the leader of the kindergarten IT group, given a tree by Ysuperman, can you find all nodes that can possibly be the root within ?
Input Format
The first line contains a positive integer , the number of nodes in the tree.
The next lines each contain two positive integers , indicating that there is an edge directly connecting and in the tree. It is guaranteed that each edge is given exactly once.
Output Format
Output at most integers in increasing order, separated by spaces, representing every node that can possibly be the root.
2
1 2
1 2
4
1 2
2 3
3 4
1 4
9
1 2
1 3
4 1
5 1
1 6
1 9
8 1
1 7
1 2 3 4 5 6 7 8 9
Hint
Sample Explanation
Sample Explanation .

When rooted at , the nodes directly connected to are . Since there is only one, all subtree sizes are the same.
When rooted at , the nodes directly connected to are . Since there is only one, all subtree sizes are the same.
So the answer is .
Sample Explanation

When rooted at , the nodes directly connected to are . Since there is only one, all subtree sizes are the same.
When rooted at , the nodes directly connected to are . Their subtree sizes are , which are not the same.
When rooted at , the nodes directly connected to are . Their subtree sizes are , which are not the same.
When rooted at , the nodes directly connected to are . Since there is only one, all subtree sizes are the same.
So the answer is .
Constraints
This problem uses bundled testdata.
| Score | ||
|---|---|---|
For of the data, .
Hint
Since the input and output sizes are large, you may need fast I/O.
Translated by ChatGPT 5