eolymp
bolt
Try our new interface for solving problems
Problems

Center of the tree

Center of the tree

Tree is given. Find its vertices for which the maximum of the distances to the remaining vertices of the tree will be minimal. \InputFile First line contains number of vertices $\:(1 \le n \le 30000)$ in the tree. The other $n - 1$ lines describe the tree. Line $i$ contains vertex number --- the parent of the vertex $i$. Vertex with number $1$ is a root of the tree. \OutputFile Print the numbers of all the required vertices in ascending order.
Time limit 1 second
Memory limit 128 MiB
Input example #1
9
1
2
2
4
4
3
3
8
Output example #1
2 3
Source 2005 Petrozavodsk, Orel STU & Udmurt SU Contest, September 1