#P3874. [TJOI2010] 砍树
[TJOI2010] 砍树
Description
We can represent this tree as a tree-structured graph, meaning there is exactly one path between any two nodes. At each node , there is a fruit with value and weight . Xiao A wants to take away a connected part (or the whole) of the tree that contains at least nodes (that is, at least fruits), such that the average value of these fruits is as high as possible. The average value is defined as the total value of the fruits divided by their total weight. Note that the part Xiao A cuts must be a connected subgraph of the original tree.
Input Format
The first line contains two numbers and , representing the number of nodes in the tree and the minimum number of fruits Xiao A should take.
The second line contains space-separated numbers, representing the value of the fruit at each node.
The third line contains space-separated numbers, representing the weight of each fruit.
The next lines each contain two numbers and (), indicating that there is an edge between nodes and . The input is guaranteed to describe a valid tree.
Output Format
Output one line containing a single number, the maximum possible average value, rounded to two decimal places.
3 1
20 10 20
1 1 1
1 2
2 3
20.00
3 2
20 10 20
1 1 1
1 2
2 3
16.67
Hint
- Constraints:
- For of the testdata, .
- For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号