Chicago-106 miles to Chicago problem


My code is not working for all the test cases as it’s giving TLE. How to optimise it?