Your code is almost correct. There is just one small logical error while comparing scores. You want to compare scores of owners of x and y and not scores of x and y. I hope this answers your query. Also this code should give tle after it passes the WA test case. You should update the owners on your way as it will decrease the levels in the tree.
for example: say this is the scenario
owner of 3 = 2 and onwer of 2 = 1 and owner of 1 = 1 This implies there is a chain 1->2->3. You can make it some thing like 1 / \ 2 3 Refer to http://www.codechef.com/viewsolution/4279768 for implementation details.
thanks for your reply…i will look into it