#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 ii, there is a fruit with value viv_i and weight wiw_i. Xiao A wants to take away a connected part (or the whole) of the tree that contains at least KK nodes (that is, at least KK 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 NN and KK, representing the number of nodes in the tree and the minimum number of fruits Xiao A should take.

The second line contains NN space-separated numbers, representing the value viv_i of the fruit at each node.

The third line contains NN space-separated numbers, representing the weight wiw_i of each fruit.

The next N1N - 1 lines each contain two numbers aia_i and bib_i (1ai,biN1 \le a_i, b_i \le N), indicating that there is an edge between nodes aia_i and bib_i. 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 20%20\% of the testdata, 1N161 \le N \le 16.
    • For 100%100\% of the testdata, 1N1001 \le N \le 100, 1KN1 \le K \le N, 1vi100001 \le v_i \le 10000, 1wi100001 \le w_i \le 10000.

Translated by ChatGPT 5