HackerRank Constructing the Tree

question:https://www.hackerrank.com/contests/hack-the-interview-vi-asia-pacific/challenges/constructing-a-tree/problem

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.