luogu#P7966. [COCI 2021/2022 #2] Hiperkocka
[COCI 2021/2022 #2] Hiperkocka
Problem Description
You are given an -dimensional hypercube.
Abstract the hypercube as a graph with vertices, labeled . Two vertices are connected if and only if is an integer power of .
Now you need to place several trees , each with edges, into this hypercube. The vertices of each tree are labeled . You are given the endpoints of the edges of the tree. Each placed tree must satisfy all of the following conditions:
- Each vertex in the tree corresponds one-to-one to a vertex of the hypercube.
- All corresponding hypercube vertices are distinct.
- For every edge in the tree, the two corresponding hypercube vertices are connected by an edge in the hypercube (i.e., the XOR of the two corresponding vertex labels is an integer power of ).
- The edge sets of any two trees, after being mapped into the hypercube, are disjoint. That is, each edge of the hypercube can belong to at most one tree.
You need to output a placement scheme so that every tree placed in the hypercube satisfies the requirements.
Input Format
The first line contains a positive integer , representing the dimension of the hypercube.
The next lines each contain two integers , indicating that in each tree , there is an edge connecting and .
Output Format
In the first line, output the number of placed trees .
In the next lines, output integers per line, representing the corresponding hypercube vertex labels for the vertices of this tree.
1
0 1
1
0 1
2
0 1
1 2
2
0 1 3
0 2 3
3
0 1
0 2
0 3
4
0 1 2 4
3 1 2 7
5 1 4 7
6 2 4 7
Hint
[Sample 3 Explanation]

[Constraints]
For of the testdata, , , and .
[Hints and Notes]
If your program correctly places trees, then the score for each test point is , where:
$$f(k)=\begin{cases} \dfrac{0.7k}{2^{n-1}} & (k \lt 2^{n-1}) \cr 1 & (k=2^{n-1}) \cr \end{cases}$$If the placement is incorrect, then the score for that test point is . It can be proven that there is always a way to place trees.
Due to the special scoring method, this problem uses a custom-written Special Judge. You are welcome to hack it.
This problem is translated from COCI 2021-2022 CONTEST #2 Task 3 Hiperkocka.
In the original COCI problem, the full score is , but for easier calculation, the full score has been changed to .
Translated by ChatGPT 5