CF237D T-decomposition
Description
You've got a undirected tree $ s $ , consisting of $ n $ nodes. Your task is to build an optimal T-decomposition for it. Let's define a T-decomposition as follows.
Let's denote the set of all nodes $ s $ as $ v $ . Let's consider an undirected tree $ t $ , whose nodes are some non-empty subsets of $ v $ , we'll call them $ x_{i} $ . The tree $ t $ is a T-decomposition of $ s $ , if the following conditions holds:
1. the union of all $ x_{i} $ equals $ v $ ;
2. for any edge $ (a,b) $ of tree $ s $ exists the tree node $ t $ , containing both $ a $ and $ b $ ;
3. if the nodes of the tree $ t $ $ x_{i} $ and $ x_{j} $ contain the node $ a $ of the tree $ s $ , then all nodes of the tree $ t $ , lying on the path from $ x_{i} $ to $ x_{j} $ also contain node $ a $ . So this condition is equivalent to the following: all nodes of the tree $ t $ , that contain node $ a $ of the tree $ s $ , form a connected subtree of tree $ t $ .
There are obviously many distinct trees $ t $ , that are T-decompositions of the tree $ s $ . For example, a T-decomposition is a tree that consists of a single node, equal to set $ v $ .
Let's define the cardinality of node $ x_{i} $ as the number of nodes in tree $ s $ , containing in the node. Let's choose the node with the maximum cardinality in $ t $ . Let's assume that its cardinality equals $ w $ . Then the weight of T-decomposition $ t $ is value $ w $ . The optimal T-decomposition is the one with the minimum weight.
Your task is to find the optimal T-decomposition of the given tree $ s $ that has the minimum number of nodes.
Input Format
N/A
Output Format
N/A