IOI '06 - Merida, Yucatan, Mexico
Mexico City is built in a beautiful valley known as the Valley of Mexico which, years ago, was mostly a lake. Around the year 1300, Aztec religious leaders decreed that the lake's center be filled in order to build the capital of their empire. Today, the lake is completely covered.
Before the Aztecs arrived,
Eventually, the kings of the cities decided to organize this commerce. They designed a commerce route that connected every city around the lake. The route met the following requirements:
- It could start in any of the cities, visited each of the cities around the lake, and finally ended in another city different from the starting city.
- The route visited each city exactly once.
- Every pair of consecutively visited cities in the route had a commercial agreement.
- Every pair of consecutively visited cities in the route was connected by a line segment.
- To avoid crashes between boats, the route never crossed itself.
The figure below shows the lake and the cities around it. The lines
(both thick and thin) represent commercial agreements between cities.
The thick lines represent a commerce route starting in city
This route never crosses itself. It would not be legal, for example, to
construct a route that went from
Cities in the lake are numbered from
Write a program that, given both the count
Input Specification
Line
Line
Next
Output Specification
If it's possible to construct the commerce route, write -1
.
If there is more than one commerce route that meets the requirements, any of them you output will be considered correct.
Grading
For test cases worth
Sample Input
7
9
1 4
5 1
1 7
5 6
2 3
3 4
2 6
4 6
6 7
Sample Output
2
3
4
1
7
6
5
Comments