Hyperloop
Time limit1sMemory limit128 MB
For odd N, print (N-1)/2 Hamiltonian cycles on the complete graph of N cities that partition all edges, using the given seat-walk construction.
- Level
Medium4 of 10
- Topics
- Greedy, Math, Implementation, Combinatorics
- Solved
- No attempts yet
Problem
In August 2013 a design appeared for a new means of transport called Hyperloop, in which capsules travel through a tube at a thousand kilometres per hour. One thing nobody knows yet: the first line will not connect two big cities, it will connect two small provincial towns. Following that example, every two of the country's cities will be joined directly by one two-way Hyperloop tube.
Once the tubes open, you have to organize several sightseeing routes. One route visits all cities, each exactly once, and returns to the city it started from, so it uses exactly tubes. To keep the traffic down, two different routes may not share a tube, no matter which way they run through it.
Because is odd, you can organize routes and leave no tube unused. Construct those routes.
Input
The first line contains the number of cities . is odd and . The cities are numbered from 1 to .
Output
Print routes, one per line. On each line print the city numbers the route visits, in order from the starting city, separated by single spaces. Do not repeat the starting city at the end.
Many sets of routes satisfy the conditions, so only the one built by the following rule is accepted.
Let . Put city 1 in the centre and place the other cities around a circle. The seats are numbered to , and seat holds city .
For , route starts at city 1, visits the cities in seats in that order, and returns to city 1, where
and every seat number is taken modulo . In other words the seats run stepping alternately forward and backward with a growing gap, which covers all seats. Print the routes in increasing order of .