#P14455. [ICPC 2025 Xi'an R] Imagined Holly

[ICPC 2025 Xi'an R] Imagined Holly

题目描述

Given a non-negative integer matrix AA of size n×nn \times n. For a tree with nn vertices, numbered from 11 to nn, we call it a holly tree\textit{holly tree} if and only if:

  • For any pair of vertices uu and vv (1u,vn1 \leq u, v \leq n), Au,vA_{u, v} equals the bitwise XOR sum of the indices of the vertices on the simple path from uu to vv in the tree.

Your task is to construct a holly tree. It is guaranteed that such a holly tree always exists.

输入格式

The first line of the input contains an integer nn (2n20002 \leq n \leq 2000), which is the size of matrix AA.

The next nn lines of the input describe the matrix AA. The ii-th line contains ni+1n - i + 1 integers Ai,i,Ai,i+1,,Ai,nA_{i, i}, A_{i, i + 1}, \ldots, A_{i, n} (0Ai,j<2110 \leq A_{i, j} < 2^{11}). Note that Ai,j=Aj,iA_{i, j} = A_{j, i} holds for all 1i,jn1 \leq i, j \leq n.

It is guaranteed that such a holly tree always exists.

输出格式

Output n1n - 1 lines, each containing two integers uu and vv (1u,vn1 \leq u, v \leq n), representing an edge of the holly tree.

2
1 3
2
1 2
4
1 3 2 5
2 0 7
3 6
4
1 2
1 3
1 4
6
1 7 4 5 2 3
2 1 6 7 0
3 5 4 3
4 3 2
5 5
6
4 1
2 3
6 4
5 2
4 2

提示

In the second example, the tree in the output is shown in the following figure:

:::align{center} :::

This tree is a holly tree. For example, for the pair of vertices (2,4)(2, 4), the simple path from 11 to 44 includes vertices 2,12, 1, and 44, with a bitwise XOR sum of 214=72 \oplus 1 \oplus 4 = 7, which satisfies the constraint A2,4=7A_{2, 4} = 7 given in the input.