Tree top view doubt

https://ide.codingblocks.com/s/63239
one test case is failing.
i hv tried many corner cases but all giving correct output.I am not getting what is going wrong in the code.
plz help!!

Hi Vishesh, consider the following input:
1 6 2 8 7 4 3 11 -1 9 -1 -1 5 -1 -1 -1 -1 10 -1 -1 -1 -1 -1

Expected Output:
11 8 6 1 2 3
Your output:
11 10 6 1 2 3

Modify your logic for this test case.