# 여행경로 - 프로그래머스
def solution(tickets):
d, ret = dict(), []
s = ['ICN']
for t in tickets:
d[t[0]] = d.get(t[0], []) + [t[1]]
d[t[0]].sort(reverse=True)
while len(s) > 0:
cur = s[-1]
if cur in d and d[cur]:
s.append(d[cur][-1])
d[cur].pop()
else:
ret.append(s.pop())
return ret[::-1]