#P4316. 绿豆蛙的归宿

绿豆蛙的归宿

Description

You are given a directed acyclic graph with nn vertices and mm edges. The start vertex is 11, and the terminal vertex is nn. Each edge has a length. From the start, every vertex is reachable, and every vertex can reach the terminal.

Green Bean Frog starts from the start and moves to the terminal. Upon arriving at a vertex that has kk outgoing edges, the frog may choose any outgoing edge to leave the vertex, and each edge is chosen with probability 1k\frac{1}{k}. What is the expected total length of the path from the start to the terminal?

Input Format

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

Lines 22 through (m+1)(m + 1) each contain three integers u,v,wu, v, w, indicating there is a directed edge from uu to vv with length ww.

Output Format

Output a single real number: the answer, rounded to two decimal places.

4 4 
1 2 1 
1 3 2 
2 3 3 
3 4 4
7.00

Hint

  • Constraints
    • For 20%20\% of the testdata, n102n \leq 10^2.
    • For 40%40\% of the testdata, n103n \leq 10^3.
    • For 60%60\% of the testdata, n104n \leq 10^4.
    • For 100%100\% of the testdata, 1n1051 \leq n \leq 10^5, 1m2×n1 \leq m \leq 2 \times n, 1u,vn1 \leq u, v \leq n, 0w1090 \leq w \leq 10^9, and the graph has no parallel edges or self-loops.

Translated by ChatGPT 5