#P7028. Decomposition
Decomposition
Problem Description
You are given an undirected complete graph with $n$ vertices ($n$ is odd). You need to partition its edge set into $k$ $\pmb{\text{disjoint simple}}$ paths, satisfying that the $i$-th simple path has length $l_i$ ($1\leq i \leq k, 1 \leq l_i \leq n-3$), and each undirected edge is used exactly once.
A complete graph is a simple undirected graph in which every pair of distinct vertices is connected by a unique edge. A simple path with length $l$ here means the path covers $l$ edges, and the vertices in the path are pairwise distinct.
It can be proved that an answer always exists if $\sum\limits_{i=1}^k l_i = \frac{n(n-1)}{2}$ holds.
Input
The first line contains an integer $T(1 \leq T \leq 100000)$ - the number of test cases. Then $T$ test cases follow.
The first line of each test case contains two integers $n, k(5 \leq n \leq 1000, 1 \leq k \leq \frac{n(n-1)}{2}, n \equiv 1 \pmod 2)$ - the number of vertices and paths.
The next line contains $k$ integers $l_1, l_2, \cdots, l_k(1 \le l_i \le n-3)$ - the length of each path.
It is guaranteed that $\sum\limits_{i=1}^k l_i = \frac{n(n-1)}{2}$ holds for each test case, and $\sum \frac{n(n-1)}{2} \leq 4 \times 10^6$.
Output
For each test case, firstly output one line containing "Case #x:", where $x(1 \leq x \leq T)$ is the test case number. Then output $k$ lines. the $i$-th line contains $l_i + 1$ numbers denoting the $i$-th path.
If there are multiple answers, print any.
$\pmb{\text{Due to technical reasons, please, do not output extra spaces at the end of each line!}}$
3
5 6
2 1 1 2 2 2
7 8
1 1 4 3 4 1 3 4
5 10
1 1 1 1 1 1 1 1 1 1
Case #1:
5 4 2
2 3
5 1
2 1 4
3 5 2
1 3 4
Case #2:
6 7
1 3
6 5 1 2 3
7 1 4 2
1 6 4 7 5
7 3
2 6 3 5
3 4 5 2 7
Case #3:
5 3
5 2
4 3
1 5
1 3
2 3
4 2
4 1
1 2
4 5