#P2081. [NOI2012] 迷失游乐园

    ID: 1021 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp图论递推2012NOI 系列Special Judge期望环套树,基环树

[NOI2012] 迷失游乐园

Description

It is vacation time. Xiao Z feels very bored staying at home, so he decides to go to the amusement park alone.

After entering the park, Xiao Z looks at the map and finds that the park can be abstracted as an undirected connected graph with nn attractions and mm roads, and the graph has at most one cycle (i.e., mm can only be equal to nn or n1n - 1).

The gate where Xiao Z is currently located also happens to be an attraction. Not knowing what is fun, he decides to start from his current position and each time randomly go to a neighboring attraction connected by a road, and never visit the same attraction twice (including the starting attraction). He will keep playing until all neighboring attractions of the current attraction have already been visited.

All the attractions Xiao Z passes through form a simple path in order. He wants to know the expected length of this path.

Xiao Z drew the abstract map of the park and brought it home, but forgot to mark which point is the gate. He has to assume that every attraction could be the gate (i.e., each attraction is equally likely to be the starting point). At the same time, each time he chooses the next attraction, he will uniformly at random choose one unvisited neighboring attraction.

Input Format

The first line contains two integers nn and mm, denoting the number of attractions and the number of roads, respectively.

The next mm lines each contain three integers Xi,Yi,WiX_i, Y_i, W_i, indicating that the endpoints of the ii-th road are XiX_i and YiY_i, and the length of this road is WiW_i. The attractions are numbered from 11 to nn. There is at most one road between any two attractions, and there are no self-loops (the graph is guaranteed to be simple).

Output Format

Output one line containing a real number, the expected length of the path, with five digits after the decimal point.

4 3
1 2 3
2 3 1
3 4 4
6.00000000

Hint

Sample Explanation

In the sample, there are 66 different paths:

路径 长度 概率
141\rightarrow 4 88 14\frac{1}{4}
212\rightarrow 1 33 18\frac{1}{8}
242\rightarrow 4 55
313\rightarrow 1 44
343\rightarrow 4
414\rightarrow 1 88 14\frac{1}{4}

Therefore, the expected length $= \frac{8}{4} + \frac{3}{8} + \frac{5}{8} + \frac{4}{8} + \frac{4}{8} + \frac{8}{4} = 6.00$.

Scoring

There are no partial scores. Your program receives full score for a test point only if the absolute error from the standard answer does not exceed 0.010.01; otherwise, you receive zero for that test point.

Constraints

For 100%100\% of the testdata, 1Wi1001 \leq W_i \leq 100.

测试点编号 nn mm 备注
11 n=10n = 10 m=n1m = n - 1 The graph is a path.
22 n=100n = 100 Only node 11 has degree greater than 22.
33 n=1000n = 1000 /
44 n=105n = 10^5
55
66 n=10n = 10 m=nm = n
77 n=100n = 100 Number of vertices on the cycle 5\leq 5.
88 n=1000n = 1000 Number of vertices on the cycle 10\leq 10.
99 n=105n = 10^5 Number of vertices on the cycle 15\leq 15.
1010 Number of vertices on the cycle 20\leq 20.

Translated by ChatGPT 5