All submissions for this problem are available.
One day, Megan bought a one-way ticket from somewhere to somewhere with some flight transfers.
For example: SFO->DFW DFW->JFK JFK->MIA MIA->ORD.
Obviously, transfer flights to a city twice, or more doesn't make sense. So Megan will not do that. Unfortunately, after she received the tickets, she messed up with the tickets and forgot the order of the tickets. Help Megan rearrange the tickets to arrange them in the correct order.
- The first line contains the number of test cases T, after which T cases follow.
- Each test case starts with an integer N. There are N flight tickets that follow.
- Each of the next 2 lines contains the source and the destination of a flight ticket.
For each test case, output one line containing "itinerary", where itinerary is sorted list of flight tickets which represents the actual itinerary. Each flight segment in the itinerary should be printed as a pair of source-destination codes.
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 100
Input: 2 1 SFO DFW 4 MIA ORD DFW JFK SFO DFW JFK MIA Output: SFO-DFW SFO-DFW DFW-JFK JFK-MIA MIA-ORD
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2|
Fetching successful submissions