Computation of a Road Network Plan
Time limit1sMemory limit128 MB
Given the number of cities n and a target diameter d, print a specific tree: a path of length d with all remaining cities hung off its middle vertex.
- Level
Easy3 of 10
- Topics
- Tree, Implementation, Math
- Solved
- No attempts yet
Problem
Byteman is planning a road trip around Byteland, but he could not get a map of the country. From his friends he learned a few facts about the Bytelandian road network:
- There are cities in Byteland, numbered from to .
- Every road is bidirectional and joins two different cities.
- For every pair of different cities there is exactly one path (a sequence of one or more roads on which no city repeats) connecting them.
- The longest such path, measured in roads, uses exactly roads.
The second and third facts together mean the network is a tree: it is connected and has no cycles, so it has exactly roads. Here is the number of roads on the longest path in that tree (its diameter).
Help Byteman reconstruct one road network that is consistent with everything he learned, or determine that no such network exists.
Input
The only line of input contains two integers and (, ), separated by a single space.
Output
If no road network satisfies the conditions, output a single line with the word BRAK (Polish for none). This happens exactly when , or when and (a tree with at least three cities always has diameter at least ).
Otherwise output exactly lines. Among all valid plans your program must print the following specific one:
- First print the roads of the main chain along cities , one per line and in order:
1 2, then2 3, and so on up tod d+1. - Let . Then, for each remaining city from to in increasing order, print the road
c j, attaching city directly to city .
Each printed line contains the two distinct city numbers of one bidirectional road, separated by a single space.
Hint
