Problem H. Tree2cycle
时间限制 8000 ms
内存限制 100 MB
A tree with N nodes and N-1 edges is given. To connect or disconnect one edge, we need 1 unit of cost respectively. The nodes are labeled from 1 to N. Your job is to transform the tree to a cycle(without superfluous edges) using minimal cost.
A cycle of n nodes is defined as follows: (1)a graph with n nodes and n edges (2)the degree of every node is 2 (3) each node can reach every other node with these N edges.
输入数据
输出数据
For each test case, please output one integer representing minimal cost to transform the tree to a cycle.
样例输入
样例输出
样例说明
In the sample above, you can disconnect (2,4) and then connect (1, 4) and (3, 4), and the total cost is 3.
$ Mathjax font initiator $