CF843C Upgrading Tree
Description
You are given a tree with $ n $ vertices and you are allowed to perform no more than $ 2n $ transformations on it. Transformation is defined by three vertices $ x,y,y' $ and consists of deleting edge $ (x,y) $ and adding edge $ (x,y') $ . Transformation $ x,y,y' $ could be performed if all the following conditions are satisfied:
1. There is an edge $ (x,y) $ in the current tree.
2. After the transformation the graph remains a tree.
3. After the deletion of edge $ (x,y) $ the tree would consist of two connected components. Let's denote the set of nodes in the component containing vertex $ x $ by $ V_{x} $ , and the set of nodes in the component containing vertex $ y $ by $ V_{y} $ . Then condition $ |V_{x}|>|V_{y}| $ should be satisfied, i.e. the size of the component with $ x $ should be strictly larger than the size of the component with $ y $ .
You should minimize the sum of squared distances between all pairs of vertices in a tree, which you could get after no more than $ 2n $ transformations and output any sequence of transformations leading initial tree to such state.
Note that you don't need to minimize the number of operations. It is necessary to minimize only the sum of the squared distances.
Input Format
The first line of input contains integer $ n $ ( $ 1
Output Format
In the first line output integer $ k $ ( $ 0
Explanation/Hint
This is a picture for the second sample. Added edges are dark, deleted edges are dotted.
