#P12826. 「DLESS-2」XOR and Tree Construction
「DLESS-2」XOR and Tree Construction
Description
Bob has an unrooted tree with vertices. Each vertex has a weight, with the weight of vertex being . Alice has recorded an matrix , where is the XOR sum of the weights of all vertices on the shortest path from vertex to vertex .
Alice observed this matrix and, to her surprise, found that all its elements are positive integers.
Unfortunately, one day, Bob lost his tree. Now, you are given Alice's matrix , and your task is to reconstruct a possible tree and the sequence of weights . It is worth noting that Alice is very reliable, so it is guaranteed that at least one such tree can always be reconstructed.
Input Format
The input consists of multiple test cases. The first line contains a single positive integer , representing the number of test cases.
For each test case:
- The first line contains a positive integer .
- The next lines describe the matrix . The -th integer on the -th of these lines is .
Output Format
For each test case:
- In the first line, output integers, representing the vertex weights .
- Then, output lines. Each line should contain two integers , representing an edge between vertex and vertex .
2
3
1 3 7
3 2 6
7 6 4
5
8 9 10 15 1
9 1 2 14 9
10 2 3 13 10
15 14 13 7 6
1 9 10 6 8
1 2 4
1 2
2 3
8 1 3 7 8
1 2
1 4
2 3
2 5
1
2
10000000000 29999508480
29999508480 20000000000
10000000000 20000000000
1 2
Hint
For all test data, it is guaranteed that:
This problem uses bundled tests. The subtasks are described as follows:
- Subtask 1 (5 pts): .
- Subtask 2 (10 pts): .
- Subtask 3 (10 pts): .
- Subtask 4 (15 pts): .
- Subtask 5 (25 pts): The values are all distinct.
- Subtask 6 (35 pts): No additional constraints.
京公网安备 11011102002149号