PROBLEM LINKS
DIFFICULTY
EASY
EXPLANATION
At each step Dunno is in some city at some time. If Roly-Poly lives in this city and the start time of the birthday party is not less than the time when Dunno get this city then the answer is “Yes”. Otherwise you need to find the closest flight from this city for the given time. If there is no flights in that city after this moment of time then the answer is “No” because Dunno will be stuck in that city forever. If he have already use the closest flight then the answer is also “No” because he will flight forever using the same sequence of flights and never gets the party. Otherwise you should use this flight, mark it as used, change your city and time to the corresponding ones and continue this procedure. Obviously we will use each flight at most once so we will have in total no more than N steps. The closest flight can be found using binary search. For example you can sort all flights by the city of arrival and then by the time of arrival and use binary search for such array. So the overall time complexity is O(N log N).
SETTER’S SOLUTION
Can be found here.
TESTER’S SOLUTION
Can be found here.