Editorial for End of the Trip


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: leefuuchang

O(N)

N = int(input()) # How many *air-routes* will be given


takeOff = set() # the set of take-off cities
landing = set() # the set of landing cities


for i in range(N): # for each *air-route*

    c_from = input() # the first line is the C_from
    takeOff.add(c_from) # add it in to the set of take-off cities

    c_to = input() # the second line is the C_to
    landing.add(c_to) # add it in to the set of landing cities


for city in landing: # for each city that we land
    if(city not in takeOff): # if we didn't leave / takeoff
        print(city) # we stay
        break

Comments

There are no comments at the moment.