#P3232. [HNOI2013 / JSOI2013] 游走

[HNOI2013 / JSOI2013] 游走

Description

Given an undirected connected graph with nn vertices and mm edges. The vertices are numbered from 11 to nn, and the edges are to be numbered from 11 to mm.

Xiao Z performs a random walk on this graph. Initially, Xiao Z is at vertex 11. At each step, Xiao Z chooses one incident edge of the current vertex uniformly at random, traverses it to the next vertex, and obtains a score equal to the label of that edge. The walk ends when Xiao Z reaches vertex nn. The total score is the sum of all scores obtained. Now, please assign labels to the mm edges so that the expected value of Xiao Z’s total score is minimized.

Input Format

The first line contains two integers, representing the number of vertices nn and the number of edges mm.

The next mm lines each contain two integers u,vu, v, indicating that there is an edge between vertices uu and vv.

Output Format

Output one real number: the answer, rounded to three decimal places.

3 3
2 3
1 2
1 3
3.333

Hint

Explanation for Sample 1

Edge (1,2)(1, 2) is labeled 11, edge (1,3)(1, 3) is labeled 22, and edge (2,3)(2, 3) is labeled 33.


Constraints

  • For 30%30\% of the testdata, it is guaranteed that n10n \leq 10.
  • For 100%100\% of the testdata, it is guaranteed that 2n5002 \leq n \leq 500, 1m1250001 \leq m \leq 125000, 1u,vn1 \leq u, v \leq n; the given graph has no multiple edges and no self-loops, and every node is reachable from 11.

Translated by ChatGPT 5