#P6074. 最小路径

最小路径

Problem Description

You are given a tree with nn nodes. Each node has two weights aia_i and bib_i. Find a simple path of length mm such that ∑ai∑bi\frac{\sum a_i}{\sum b_i} is minimized. If there is no solution, output −1-1.

Input Format

The first line contains two positive integers nn and mm.
The second line contains nn positive integers aia_i.
The third line contains nn positive integers bib_i.
The following n−1n - 1 lines each contain two positive integers u,vu, v, which are the two endpoints of an edge.

Output Format

Output the minimum value, rounded to two decimal places.

3 1
2 3 3
6 6 6
1 2
2 3
0.42
9 2
9 4 4 1 6 5 1 9 5
8 3 3 1 5 4 1 8 4
1 2
2 3
3 4
3 5
1 6
6 7
7 8
6 9
1.15

Hint

Subtask 1 (2020 points): n≤100n \le 100, m≤nm \le n, 1≤ai,bi≤20001 \le a_i, b_i \le 2000.

Subtask 2 (4040 points): n≤104n \le 10^4, m≤nm \le n, 1≤ai,bi≤20001 \le a_i, b_i \le 2000.

Subtask 3 (4040 points): n≤2×105n \le 2 \times 10^5, m≤nm \le n, 1≤ai,bi≤20001 \le a_i, b_i \le 2000.

For 100%100\% of the testdata: 1≤n≤2×1051 \le n \le 2 \times 10^5, 1≤m≤n1 \le m \le n, 1≤ai,bi≤20001 \le a_i, b_i \le 2000.

Translated by ChatGPT 5