Compressed Spanning Subtrees
Time limit2sMemory limit256 MB
Reconstruct a hidden tree with no degree-two vertices by asking how many vertices the compressed spanning subtree of a chosen set contains.
- Level
Hard9 of 10
- Topics
- Tree, Divide and conquer, Implementation
- Solved
- No attempts yet
Problem
Consider a tree with vertices numbered from 1 to . For a set of spanned vertices (vertices not in are called not spanned), the compressed spanning subtree is computed as follows.
- Set .
- If a not spanned vertex has exactly one incident edge, remove it together with that edge.
- Repeat step 2 while the condition still holds.
- If a not spanned vertex has exactly two incident edges, remove it together with both edges and add a new edge connecting the two other endpoints.
- Repeat step 4 while the condition still holds.
Formally, is the smallest subgraph of that contains all vertices of , after every other vertex of degree two or less is smoothed out.

The tree from test 1, and its compressed spanning subtrees for and .
The tree is not given to you. Your task is to find it. You can ask questions of this form: "How many vertices does the compressed spanning subtree of contain?" Without a guarantee, finding the tree this way would be impossible, so has no vertex with exactly two incident edges.