3322: Computer Net

内存限制:64 MB 时间限制:2.000 S
评测方式:文本比较 命题人:
提交:7 解决:1

题目描述

Computer net is created by consecutive computer plug-up to one that has already been connected to the net. Each new computer gets an ordinal number, but the protocol contains the number of its parent computer in the net. Thus, protocol consists of several numbers; the first of them is always 1, because the second computer can only be connected to the first one, the second number is 1 or 2 and so forth. The total quantity of numbers in the protocol is N − 1 (N is a total number of computers). For instance, protocol 1, 1, 2, 2 corresponds to the following net:
1 - 2 - 5
|   |
3   4
The distance between the computers is the quantity of mutual connections (between each other) in chain. Thus, in example mentioned above the distance between computers #4 and #5 is 2, and between #3 and #5 is 3.
Definition. Let the center of the net be the computer which has a minimal distance to the most remote computer. In the shown example computers #1 and #2 are the centers of the net.
Your task is to find all the centers using the set protocol.

输入

The first line of input contains an integer N, the quantity of computers (2 ≤ N ≤ 10000). Successive N − 1 lines contain protocol.

输出

Output should contain ordinal numbers of the determined net centers in ascending order.

样例输入 复制

5
1
1
2
2

样例输出 复制

1 2

提示