Baltic OI '03 P2 - Gems

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 2.0s
Memory limit: 64M

Problem types
Baltic Olympiad in Informatics: 2003 Day 1, Problem 2

The Gem-Toys Company asked you to solve the following problem.

You are given a connected acyclic graph, i.e. a set of vertices connected by edges in such a way that from each vertex you can reach all the other vertices by traversing the edges, and it does not contain a loop.

The Gem-Toys Company is going to produce jewelry models of such graphs. Vertices will be made of gems and edges will be made of gold string. It is required that adjacent vertices are made of different kinds of gems. For each positive integer p there is exactly one kind of gems with the price p.

Your task is to write a program computing the minimal total price of the gems needed to make the model.

Input Specification

The first line of the input contains one positive integer N (1 \le N \le 10\,000), the number of vertices. The vertices are numbered from 1 to N. The following N-1 lines describe the edges, one per line. Each of these lines contains a pair of integers A and B separated by a space (1 \le A, B \le N, A \neq B). Such a pair represents an edge connecting vertices A and B.

Output Specification

The first and only line of the output must contain one integer: the minimal total price of the gems needed to make the model.

Sample Input

8
1 2
3 1
1 4
5 6
1 5
5 7
5 8

Sample Output

11

Comments

There are no comments at the moment.