CF1057A.Bmail Computer Network

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Bmail Computer Network

Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values pip_i — the index of the router to which the ii-th router was connected after being purchased (pi<ip_i \lt i).

There are nn routers in Boogle in total now. Print the sequence of routers on the path from the first to the nn-th router.

Input

The first line contains integer number nn (2n2000002 \le n \le 200000) — the number of the routers. The following line contains n1n-1 integers p2,p3,,pnp_2, p_3, \dots, p_n (1pi<i1 \le p_i \lt i), where pip_i is equal to index of the router to which the ii-th was connected after purchase.

Output

Print the path from the 11-st to the nn-th router. It starts with 11 and ends with nn. All the elements in the path should be distinct.

Samples

8
1 1 2 2 3 2 5
1 2 5 8 
6
1 2 3 4 5
1 2 3 4 5 6 
7
1 1 2 3 4 3
1 3 7 

在线编程 IDE

建议全屏模式获得最佳体验