#P2770. 航空路线问题
航空路线问题
Description
Given an airline map in which vertices represent cities and edges represent direct routes between two cities, and no two cities lie on the same meridian. Find a travel route that satisfies the following constraints and visits the maximum number of cities.
-
Start from the westernmost city, fly strictly from west to east through several cities to the easternmost city, then fly strictly from east to west back to the starting city (possibly via several cities).
-
Except for the starting city, any city may be visited at most once.
For the given airline map, design an algorithm to find an optimal airline travel itinerary that meets the requirements.
Input Format
The first line contains two integers separated by a space, the number of vertices and the number of edges .
Lines to : each line contains a string. The -th line gives the name of the -th city from west to east.
Lines to : each line contains two strings , indicating that there is a direct route between city and city .
Output Format
This problem uses Special Judge.
First determine whether there exists a route that meets the requirements. If it exists, output one valid itinerary.
If a route exists, output:
- On the first line, output an integer , the maximum number of cities visited.
- Then output lines, one string per line. The -th line contains the name of the -th city in the itinerary. Note that the -st and the -th cities are necessarily the starting city.
Otherwise, output a single line containing the string No Solution!.
8 9
Vancouver
Yellowknife
Edmonton
Calgary
Winnipeg
Toronto
Montreal
Halifax
Vancouver Edmonton
Vancouver Calgary
Calgary Winnipeg
Winnipeg Toronto
Toronto Halifax
Montreal Halifax
Edmonton Montreal
Edmonton Yellowknife
Edmonton Calgary
7
Vancouver
Edmonton
Montreal
Halifax
Toronto
Winnipeg
Calgary
Vancouver
Hint
Constraints and Notes
For of the testdata, it is guaranteed that , , the length of does not exceed and contains only letters and digits, are city names given in the input, and no pair appears more than once.
Translated by ChatGPT 5
京公网安备 11011102002149号