Vera and Trail Building
Time limit1sMemory limit512 MB
Given K, follow a fixed greedy decomposition into complete blocks and print the resulting connected trail network with exactly K two-edge-disjoint paths.
- Level
Easy3 of 10
- Topics
- Greedy, Graph, Implementation, Math
- Solved
- No attempts yet
Problem
Vera loves hiking and is building her own trail network. The network has places numbered to and bidirectional trails, where trail directly joins two distinct places and . The network has to be connected, so it is possible to hike between any two places along the trails. More than one trail may directly join the same pair of places.
Two places and with form a beautifully connected pair if Vera can hike from to and then back to without hiking on the same trail more than once. Vera calls her network beautiful if it has exactly beautifully connected pairs.
Vera does not want her network to be too large, so it has to satisfy .
For almost every many beautiful networks exist, so this problem asks for one specific network. The output section states exactly which one to print.
Input
The first line contains one integer ().
Output
Build the network with the rule below and print it. Nothing else is accepted.
First split into blocks. Start with an empty list and repeat while : take the largest integer with and , append to the list, then replace by . Call the resulting list and let .
Number the places to and give every block a consecutive range of places: block takes places to , block takes the next places, and so on. Write for the first place of block and for its last place.
The first line of the output contains and , separated by one space. Each of the next lines contains the two places of one trail, separated by one space, in the order described here.
For , print the trails of block :
- if , print the line " " twice;
- if , print the trails , , up to , and then , one per line, each with its first place written first.
After the trails of all blocks, print the joining trails: for , print the line " ".
This network is connected, has exactly beautifully connected pairs, and satisfies and for every allowed .
Note
In the first example , so the blocks are and . Places and are joined by two trails, places and are joined by two trails, and the trail between places and joins the two blocks. The two beautifully connected pairs are and .
In the second example , so there is one block with and the network is a cycle on four places. All six pairs of places form a beautifully connected pair.