연결된 다중 그래프에서 간선 가중치들의 평균으로부터의 제곱 편차 합으로 정의되는 분산이 최소가 되는 신장 트리를 찾는다.
어려움9최소 신장 트리그리디정렬수학아직 제출이 없습니다시간 제한1초메모리 제한256 MBSophie learned today that the notion of variance can be extended to edge-weighted trees: given a tree with edges E this is a sum (over E) 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_e denotes the weight of the edge e 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 n and m (2≤n≤10,000, 1≤m≤10,000), denoting the number of vertices and edges of the graph. Each of the following m lines contains three positive integers a_i, b_i and w_i (1≤a,b≤n, a=b, 1≤w≤100,000), this is the description of the ith edge, which connects the vertices a_i and b_i and has the weight w_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 10−6.