Just calculat
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

There is an acyclic graph with n points and n-1 edges (we can also call it a tree). The number of the node is 1~n. Each edge has a weight  w. We know that there is a shortest path between the two nodes u, v. For this shortest path, we use:
    f(u,v) represents the average of all edge weights on the path
    d(u,v) represents the number of edges on the path
    s(u,v) represents the set of points passing on the path (including u, v)
Now there is a simple question, we only need to calculate

输入描述:

The first line enters two integers n, x, where n represents the number of nodes and x represents the value of x in the above formula.
Next n-1 lines, input three integers u, v, w for each line, represent that there is a path with a weight of w between node u and node v.
Data guarantee: 1 < n < = 1e5, 1<=x<n, 1 <= u, v <= n, 1 <= w < = 1e4.
Guaranteed input must be a tree

输出描述:

Output the result of the formula, accurate to three decimal places.
If there is no value that satisfies the condition, directly output -1.
示例1

输入

复制
5 2
1 2 4
2 3 2
3 4 3
3 5 4

输出

复制
3.333

说明

u=5, v=1 can get the maximum
示例2

输入

复制
5 2
1 2 2
2 3 4
3 4 3
3 5 4

输出

复制
4.000

说明

u=5, v=2 can get the maximum
示例3

输入

复制
3 2
1 2 1
1 3 1

输出

复制
-1

说明

Can't find u, v meets all of the above conditions