Problem D
Parents
A certain software architect stores hierarchical data by assigning a parent to each item. While explaining his idea he drew the following table and chart on the whiteboard.
ID |
Parent |
Item |
0 |
-1 |
Geometry |
1 |
0 |
Polyhedron |
2 |
1 |
Prism |
3 |
1 |
Platonic Solid |
4 |
3 |
Tetrahedron |
5 |
3 |
Cube |
6 |
3 |
Icosahedron |
7 |
1 |
Pyramid |
8 |
0 |
Polygon |
9 |
8 |
Triangle |
10 |
8 |
Quadrilateral |
11 |
10 |
Parallelogram |
12 |
10 |
Rectangle |
13 |
12 |
Square |
![\includegraphics[width=\textwidth ]{diagram.png}](/problems/parents/file/statement/en/img-0001.png)
The architect needs to find the deepest item(s). Write a program to print the deepest items in the heirarchy in alphabetical order. In the example above, there is only one deepest item: Square. If however, Square were not included in the example above, five deepest items exist: Tetrahedron, Cube, Icosahedron, Parallelogram, and Rectangle.
Input
The first line of input contains the number (
Output
Each data set should produce one line of output containing the deepest items in alphabetical order.
Sample Input 1 | Sample Output 1 |
---|---|
2 14 -1 geometry 0 polyhedron 1 prism 1 platonicsolid 3 tetrahedron 3 cube 3 icosahedron 1 pyramid 0 polygon 8 triangle 8 quadalateral 10 parallelogram 10 rectangle 12 square 13 -1 geometry 0 polyhedron 1 prism 1 platonicsolid 3 tetrahedron 3 cube 3 icosahedron 1 pyramid 0 polygon 8 triangle 8 quadalateral 10 parallelogram 10 rectangle |
square cube icosahedron parallelogram rectangle tetrahedron |