Hostel Visit , Output is correct but not passing test cases

correct the code and please add comments where correction is done

@as159925 firstly, you dont need to check for the constraints like you have, constraints are provided to give you an idea about the type of dataype to use and what should be time complexity of the program.
Secondly, the distance can be quite big, so you will have to use the datatype long long int.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.