#P3319. [SDOI2015] 嫁接树
[SDOI2015] 嫁接树
Description
{{Alice designed a tree with nodes (including the root), numbered consecutively from to , connected by edges. Later, Bob added new edges that did not exist before (i.e., they are neither self-loops nor parallel edges), and called the resulting graph a "-grafted tree".
Now Alice wants to color every node of the grafted tree using exactly available colors, numbered to . Adjacent nodes must be colored differently. Suppose the number of nodes colored with color is . 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 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 integers and , as described. Lines through each contain two integers and , giving the edges. First, the 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 .
, , .}}
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
京公网安备 11011102002149号