Minimal Variance Tree

연결된 다중 그래프에서 간선 가중치들의 평균으로부터의 제곱 편차 합으로 정의되는 분산이 최소가 되는 신장 트리를 찾는다.

어려움9최소 신장 트리그리디정렬수학아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

Sophie learned today that the notion  of variance can be extended to edge-weighted trees: given a tree with edges EE this is a sum (over  EE) of squared differences between the weights of the edges and the mean weight of the edges. She was able to come up with a formula for that: if w_ew\_e denotes the weight of the edge ee then the variance of the tree is

 \[\sum_{e \in E} \left( w_e - S_T \right)^2 \mbox{, where } S_T = \sum_{e \in E}  \frac{w_e}{|E|}\enspace .\] 

Sophie wonders, whether for a given multigraph she can compute its spanning tree with the  smallest variance. Help her in this task.

입력

First line of the input contains two positive integers nn and mm (2n10,000(2 \leq n \leq 10\\,000, 1m10,000)1 \leq m \leq 10\\,000), denoting the number of vertices and edges of the graph. Each of the following mm lines contains three positive integers a_ia\_i, b_ib\_i and w_iw\_i (1a,bn(1 \leq a, b \leq n, aba \neq b, 1w100,000)1 \leq w \leq 100\\,000),  this is the description of the iith edge, which connects the vertices a_ia\_i and b_ib\_i and has the weight w_iw\_i.

The described graph is connected, it can have many edges between any two vertices, those edges can have different weights.

출력

You should  one real number: minimal value of variance of a spanning tree of the given graph. The answer is accepted if the relative or absolute error is at most 10610^{-6}.