#Q86. 「一本通 3.3 练习 1」最小圈

    ID: 2169 Type: Default 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>二分分数规划HNOI早于 2010负环一本通提高

「一本通 3.3 练习 1」最小圈

Description

Original source: HNOI 2009

Consider a weighted directed graph G=(V,E)G=(V,E) with w:ERw:E\to R, where each edge e=(i,j)(ij,iV,jV)e=(i,j)(i\not =j,i\in V,j\in V) has a weight defined as wi,jw_{i,j}. Let n=Vn=|V|. A cycle c=(c1,c2,,ck)(ciV)c=(c_1,c_2,\cdots ,c_k)(c_i\in V) in GG exists if and only if both (ci,ci+1)(1i<k)(c_i,c_{i+1})(1\le i\lt k) and (ck,c1)(c_k,c_1) are in EE, where kk is called the length of cycle cc. Let ck+1=c1c_{k+1}=c_1, and define the average value of cycle c=(c1,c2,,ck)c=(c_1,c_2,\cdots ,c_k) as:

μ(c)=1ki=1kwci,ci+1\mu (c)=\frac{1}{k}\sum_{i=1}^k w_{c_i,c_{i+1}}

That is, the average of the weights of all edges in cc.

Let μ(c)=min{μ(c)}\mu^*(c)=\min \{\mu (c)\} be the minimum average value among all cycles cc in GG. The goal is: given a graph G=(V,E)G=(V,E) and w:ERw:E\to R, compute the minimum average value μ(c)=min{μ(c)}\mu ^* (c)=\min \{ \mu (c)\} of all cycles cc in GG.

Input Format

The first line contains two positive integers nn and mm, separated by a space, where n=Vn=|V| and m=Em=|E|, representing the number of vertices and edges in the graph, respectively.

The next mm lines each contain three space-separated numbers i,j,wi,ji,j,w_{i,j}, indicating an edge (i,j)(i,j) with weight wi,jw_{i,j}.

The input guarantees that the graph G=(V,E)G=(V,E) is connected, contains at least one cycle, and has at least one vertex that can reach all other vertices.

Output Format

Output only one real number μ=min{μ(c)}\mu ^*=\min \{ \mu (c) \}, rounded to 8 decimal places.

Sample 1

4 5
1 2 5
2 3 5
3 1 5
2 4 3
4 1 3

3.66666667

Sample 2

2 2
1 2 -2.9
2 1 -3.1

-3.00000000

Data Range and Hints

For 20%20\% of the data, 1n100,1m10001\le n\le 100,1\le m\le 1000;
For 40%40\% of the data, 1n1000,1m50001\le n\le 1000,1\le m\le 5000;
For 100%100\% of the data, 1n3000,1m104,wi,j1071\le n\le 3000,1\le m\le 10^4,|w_{i,j}|\le 10^7.

The input ensures 1i,jn1\le i,j\le n.