TCP: Travelling Chef problem

How is this code correct http://www.codechef.com/viewsolution/3786481 ?
Or it gave AC due to something wrong with the test cases or anything…