#P14105. [ZJCPC 2017] Heap Partition
[ZJCPC 2017] Heap Partition
题目描述
A sequence is called if there exists a binary tree with nodes such that every node is labelled with exactly one element from the sequence , and for every non-root node and its parent , and hold. Each element in sequence can be used to label a node in tree only once.
Chiaki has a sequence , she would like to decompose it into a minimum number of heapable subsequences.
Note that a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
输入格式
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:
The first line contain an integer () -- the length of the sequence.
The second line contains integers ().
It is guaranteed that the sum of all does not exceed .
输出格式
For each test case, output an integer denoting the minimum number of heapable subsequences in the first line. For the next lines, first output an integer , indicating the length of the subsequence. Then output integers in increasing order on the same line, where means the index of the -th element of the -th subsequence in the original sequence.
4
4
1 2 3 4
4
2 4 3 1
4
1 1 1 1
5
3 2 1 4 1
1
4 1 2 3 4
2
3 1 2 3
1 4
1
4 1 2 3 4
3
2 1 4
1 2
2 3 5