E - Snowflake Tree Editorial by en_translator
In the construction of a Snowflake Tree, let us call the vertex prepared in step 2 the center, and the \(x\) vertices prepared in step 3 the first layer. Also, let \(d_v\) the degree of vertex \(v\) in tree \(T\).
Fix a vertex \(u\) to become the center, and the number of first-layer vertices \(x\). If vertices \(v_1,v_2,\dots,v_x\) are chosen for the first layer, the maximum value that can be chosen for \(y\) is \(\max\{d_{v_1},d_{v_2},\dots,d_{v_x}\}-1\). Thus, among the vertices adjacent to \(u\), it is optimal to choose the \(x\) vertices with the largest degrees.
Therefore, if the vertices adjacent to \(u\) in descending order of their degrees so that \(d_{v_1} \geq d_{v_2} \geq \dots d_{v_{d_u}}\), once the number of vertices \(x\) in the first layer is fixed, a Snowflake Tree with \((1+x+xy)\) vertices can be constructed, where \(y=d_{v_x}-1\). Here, \(N-(1+x+xy)\) vertices need to be removed.
The problem can be solved by iterating through \(u\) and \(x\) exhaustively, counting the number of vertices to be removed, and finding their minimum value. The time complexity is \(O(N \log N)\), where sorting is the bottleneck.
(While the construction of Snowflake Tree does not allow \(y=0\), a Snowflake Tree with \(x=1\) and \(y=n-1\) cane be regarded as that with \(x=1\) and \(y=n-1\), so we do not need to rule out \(y=0\).)
posted:
last update: