Editorial
The last added vertex was connected either to every previous vertex or to none of them. Therefore, when vertices remain, we can remove a vertex of degree or degree . Repeating this until one vertex remains reconstructs the insertion order and the operation used for every inserted vertex in reverse.
We can implement the removal process efficiently. Let be the degree of vertex in the original graph, and let be the number of removed universal vertices. Every removed universal vertex was adjacent to every vertex that still remains, while every removed isolated vertex was adjacent to none of them. Thus, the current degree of every remaining vertex is
When vertices remain, we may remove either of the following.
- A vertex with is currently isolated.
- A vertex with is currently universal.
Place the vertices into buckets by their original degrees. The required vertex can then be removed in per step. One of the two kinds is always available because every input satisfies the condition. Including the computation of the initial degrees, reconstruction takes time.
Now follow the removal history in reverse and assign brightnesses. Give the first vertex brightness
Let and be the minimum and maximum brightness assigned so far.
- For an isolated vertex, assign . Its sum with every existing brightness is at most , so it creates no edge.
- For a universal vertex, assign . Its sum with every existing brightness is greater than , so it is connected to every existing vertex.
It remains to show that every brightness lies between and . The invariant
holds after every step. Also, adding one vertex increases by at most one, so throughout the construction. Together, these properties imply and .
The time complexity is , and the space complexity is also .
Solution written by GPT6