P3023 [USACO11OPEN] Soldering G

题目描述

The cows are playing with wires! They have learned a technique called soldering, in which they connect two pieces of wire together by attaching the endpoint of one wire to a location along the length of the other. (Soldering endpoint to endpoint is not allowed.) There can be multiple solder junctions at the same point. The cows have a plan for an Amazing Structure they would like to build. It is in the form of a graph with N (1

输入格式

\* Line 1: A single integer: N \* Lines 2..N: Two space-separated integers describing an edge: A and B

输出格式

\* Line 1: A single integer, the cost of soldering the tree together. Note that this number may not always fit in a 32-bit integer.

说明/提示

Since all nodes in the structure are connected to node 1, we only need to buy one wire of length 2 and three of length 1, for a total cost of 2 \* 2 + 1 \* 1 + 1 \* 1 + 1 \* 1 = 7.