#P5765. [CQOI2005] 珠宝

[CQOI2005] 珠宝

Description

There is a tree with nn nodes. Assign a positive integer label to each node so that adjacent nodes have different labels, and the total sum of labels is as small as possible.

Input Format

The first line contains an integer nn.

The following n1n-1 lines each contain two integers u,v (1u,vn)u, v \ (1\le u, v\le n), indicating that there is an edge between uu and vv.

Output Format

Only one line, the minimum possible sum of labels.

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

Hint

For 20%20\% of the testdata, n10n\le 10.

For 40%40\% of the testdata, n1000n\le 1000.

For 100%100\% of the testdata, 1n500001\le n\le 50000.

Translated by ChatGPT 5