#P3319. [SDOI2015] 嫁接树

[SDOI2015] 嫁接树

Description

{{Alice designed a tree with NN nodes (including the root), numbered consecutively from 11 to NN, connected by N1N - 1 edges. Later, Bob added KK new edges that did not exist before (i.e., they are neither self-loops nor parallel edges), and called the resulting graph a "KK-grafted tree".

Now Alice wants to color every node of the grafted tree using exactly NN available colors, numbered 11 to NN. Adjacent nodes must be colored differently. Suppose the number of nodes colored with color ii is tit_i. Bob gives the following score:

$$\mathit{score}=\dfrac{t_1+\dfrac{1}{2}t_2+\dfrac{1}{3}t_3+\cdots+\dfrac{1}{N}t_N}{1+P\times (t_1+2t_2+3t_3+\cdots+Nt_N)}$$

Here PP is a non-negative coefficient. Alice wants to find a coloring that maximizes Bob’s score. Can you help her?}}

Input Format

{{The first line contains 22 integers NN and KK, as described. Lines 22 through N+KN+K each contain two integers uu and vv, giving the N+K1N+K-1 edges. First, the N1N - 1 tree edges are given, then the newly added edges. There are no self-loops or parallel edges. The last line contains a non-negative floating-point number PP.

K2K \le 2, 1N2×1051 \le N \le 2 \times 10^5, 0P<100 \le P < 10.}}

Output Format

{{Output the maximum possible score, rounded to three decimal places.}}

9 0
1 2
1 3
1 4
1 5
2 6
2 7
2 8
2 9
2.5
0.253

Hint

{{2024-10-11 update: Updated the testdata precision issue.}}

Translated by ChatGPT 5