Editorial for CEOI '22 P3 - Prize
Submitting an official solution before solving the problem yourself is a bannable offence.
Prepared by: Ivan Paljak and Josip Klepec
Setup
Summarization of the task is somehow choosing the
(DMOJ editor's note: Go here to read Algorithm 1)
The subset
(DMOJ editor's note: Go here to read Algorithm 2)
Each query may also give some lowest common ancestor which is not in
We define
Lemma 0.1.
We will describe the algorithm for making such small tree. It can be applied to both
(DMOJ editor's note: Go here to read Algorithm 3)
Now for these trees, we want to reconstruct the weights of edges. For each tree, we have
Lemma 0.2. Those paths are such that they uniquely determine the tree.
The proof is not too hard so we won't go into too much detail. Firstly, imagine we construct a graph as described in section for Full Points (see section couple lines below).
Now, all we need to prove is that that graph is connected. There is no need to prove that the given set of queries doesn't give a contradiction because we can rely on the authentication of the interactor.
We can prove the connectivity by analyzing how we constructed the queries. The connectivity becomes very obvious very quickly after we realize that we first sorted the node labels and then asked of adjacent ones. Every pair of adjacent node labels being connected means the whole set is.
Subtask 3
Even though it is not necessary for full points we can use Gaussian elimination to solve this subtask. Every query forms some equation (with variables being edge weights in respective trees). Now we get two linear systems, one for each tree and we just solve each independently.
https://cp-algorithms.com/linear_algebra/linear-system-gauss.html
Subtask 4
It is not hard to modify the algorithm for constructing the small tree to reconstruct the weights as well if our queries are also sorted by the preorder. But it only holds for the second tree. To achieve this for both trees we need to find a set of node labels such that they can be ordered in a way that they form a monotonic sequence with respect to the preorder in the first tree, but also in the second tree.
One could always choose such a subset because
If we order node labels with respect to preorder in tree
Theorem 0.3 (Erdos-Szekeres). For given positive natural numbers
Full Points
Method 1
For a rooted tree we denote
Then our queries give equations of the form:
Now, we construct a weighted directed graph by adding an edge from
Now to find
When we reconstructed
This gives us an algorithm with complexity
Method 2
Alternatively, one could solve the system of equations by using Gaussian elimination faster by observing that each equation forms a path in a tree. Furthermore, a path goes from some node to the root of the tree (meaning lca of endpoints of the path is always on them).
(DMOJ editor's note: Go here to read Algorithm 4)
At first, this gives us complexity
Comments