Dynamic Centroid
Time limit1.5sMemory limit512 MB
For each prefix tree formed by vertices 1..k, output the smallest centroid (the vertex whose removal leaves components of size at most k/2).
- Level
Hard8 of 10
- Topics
- Tree, DFS, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
In a tree with vertices, a centroid is a vertex such that every subtree obtained by splitting the tree at that vertex has size at most . Every tree is known to have a centroid.
Vertex 1 is the root of the tree, the parent of vertex is , and .
For each from to , find the centroid of the tree that uses only vertices 1 through .
Input
The first line gives . ()
The second line gives for through , separated by spaces. ()
Output
For each from to , print the number of the centroid of the tree that uses only vertices 1 through , separated by spaces, in order. If several answers exist, print the smallest one.