#P10857. Valid Root Pair Construction in a Full Binary Tree
Valid Root Pair Construction in a Full Binary Tree
Valid Root Pair Construction in a Full Binary Tree
You are given a positive integer \(h\). Define \(n = 2^h - 1\). For each positive integer \(u\) (\(1 \le u \le n\)) and for each positive integer \(k\) (\(1 \le k \le 2h-2\)), a value \(f_{u,k}\) is provided.
Your task is to find a pair of numbers \((r, w)\) such that:
- \(1 \le r \le n\) and \(0 \le w < 2^{30}\).
- There exists a full binary tree \(T\) of height \(h\) with the following properties:
- The nodes of \(T\) are numbered by a permutation of \(\{1, 2, \dots, n\}\), and every node has an associated weight (an integer in \(\left[0, 2^{30}\right)\).
- The root of \(T\) is the node numbered \(r\) and its weight is \(w\).
- For every node numbered \(u\) (\(1 \le u \le n\)) and every positive integer \(k \le 2h-2\), if we denote by \(\operatorname{dis}(u,v)\) the number of edges on the simple path between node \(u\) and node \(v\) (with \(\operatorname{dis}(u,u)=0\)), then the XOR of the weights of all nodes \(v\) satisfying \(\operatorname{dis}(u,v)=k\) is exactly \(f_{u,k}\). (If no such node exists for a given \(u\) and \(k\), then it is required that \(f_{u,k}=0\).)
The problem guarantees that there is at least one valid pair \((r, w)\) meeting the conditions. You need to output any such pair.
Note: All formulas must be written in LaTeX format.
inputFormat
The input is given as follows:
- The first line contains a single integer \(h\) \((1 \le h \le \text{upper bound})\).
- If \(h \ge 2\), then the next \(n = 2^h - 1\) lines follow. The \(i\)-th of these lines contains \(2h-2\) space-separated integers representing \(f_{i,1}, f_{i,2}, \dots, f_{i,2h-2}\). For the case \(h=1\), no additional lines are provided.
It is guaranteed that the given values satisfy the condition that at least one valid pair \((r, w)\) exists.
outputFormat
Output two space‐separated integers \(r\) and \(w\) that represent a valid answer as described in the problem statement.
sample
1
1 0