Palo Alto Networks Interview Question

save relations between nodes and then print the tree.