创建于 2026/07/18 · 更新于 2026/07/18
Given positive integer and non-negative integer sequence .
You have to construct a rooted tree with nodes, labeld .
Let be the number of edges on the unique simple path between the root and node on tree .
You need to maximize , where is defined as the smallest non-negative integer that is not in set .
You need to solve testcases for each test data.
The first line of input contains a single integer (). Then testcases follows.
The first line of each testcase contains a single integer ().
The second line of each testcase contains integers ().
It is guaranteed that the sum of over all testcases in a single testdata does not exceed .
For each testcase, you should output two lines.
The first line of each testcase contains one integer , the maximum .
The second line of each testcase contains non-negative integers . means that node is the root of , otherwise is the label of the parent of node on .
If there are several possible s, you may output any of them.
3
3
0 2 0
7
1 0 4 1 0 2 6
1
1
2
0 1 1
6
2 0 2 1 2 1 2
0
0