Edge-Disjoint Spanning Trees
Time limit2sMemory limit512 MB
Given N and K, output K edge-disjoint spanning trees of the complete graph on N vertices, or -1 if impossible.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
You are given a complete graph with vertices. Find spanning trees that are edge-disjoint.



The leftmost figure above shows a complete graph with four vertices. The two figures to the right are two spanning trees of this graph that share no edge.
Input
You are given two integers and on a single line (, ).
Output
If there is no tuple of spanning trees that satisfies the conditions, print .
Otherwise, print spanning trees. Each spanning tree must be printed on lines. The -th line must contain two space-separated integers: the two endpoints of the -th edge. The vertices are numbered through . You may print an empty line between consecutive trees.