#P9890. Knight Duel Tournament Scheduling
Knight Duel Tournament Scheduling
Knight Duel Tournament Scheduling
DreamGrid, the king of Gridland, is organizing a knight tournament. There are knights, numbered from 1 to , participating in the tournament. The tournament consists of rounds. In each round, every knight must participate in exactly one duel, and each duel is fought by exactly two knights. Moreover, every pair of knights may duel each other at most once over all rounds.
In addition, the following condition must hold: For any two distinct rounds and and any four distinct knights , , , and , if in round knight fights knight and knight fights knight , and in round knight fights knight , then in round knight must fight knight .
Your task is to output an arrangement of duels for the rounds that satisfies all of the rules above. It is guaranteed that is even and , so that a valid arrangement exists. A standard round-robin (circle) scheduling algorithm will satisfy all the conditions.
inputFormat
The input consists of a single line containing two space-separated integers: and , where:
- is an even integer representing the total number of knights.
- is the number of rounds ().
outputFormat
Output exactly lines. Each line corresponds to one round and should contain exactly pairs of knights. For each pair, output the two knight numbers separated by a space. Different pairs on the same line should also be separated by a space. The schedule must satisfy all tournament rules described above.
sample
4 3
1 4 2 3
1 3 4 2
1 2 3 4
</p>