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

[ICPC 2025 Xi'an R] Imagined Holly

[ICPC 2025 Xi'an R] Imagined Holly

题目描述

Given a non-negative integer matrix $A$ of size $n \times n$. For a tree with $n$ vertices, numbered from $1$ to $n$, we call it a $\textit{holly tree}$ if and only if:
  • For any pair of vertices uu and vv (1≤u,v≤n1 \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 $n$ ($2 \leq n \leq 2000$), which is the size of matrix $A$.

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

It is guaranteed that such a holly tree always exists.

输出格式

Output $n - 1$ lines, each containing two integers $u$ and $v$ ($1 \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 2⊕1⊕4=72 \oplus 1 \oplus 4 = 7, which satisfies the constraint A2,4=7A_{2, 4} = 7 given in the input. 标签: P14455|2025|Special Judge|ICPC|西安

来源

P14455|[ICPC 2025 Xi'an R] Imagined Holly