HackerRank Constructing the Tree

question:Programming Problems and Competitions :: HackerRank

i have tried a lot but not able to construct the tree.
i am not able to understand the code please can any one write in easy language.