Time limit: 1 second Memory limit: 256 MB Source: practical exam of the 24th Computer…
- User
Time limit: 1 second Memory limit: 256 MB Source: practical exam of the 24th Computer Olympiad course Winter is cold and heavy snowfall has blocked the roads. Mr. Engineer has gone to city 1 for a work project and is going to his house in city no n n is supposed to return. On any given day, he can stay in the city he is in or take one of the unblocked roads connected to that city. Mr. Engineer has obtained very useful information from the Meteorological Organization and knows the probability of any road being blocked. Note that a road is blocked on one day, regardless of whether or not it was blocked on the previous days. For example, if the possibility of a road being blocked p take p, the probability that the road is blocked two days in a row, p 2 p 2 and the probability that it is not closed on any of the two days, ( p
1 ) 2 (p−1) 2 is Crossing each road takes exactly one day.
Now, if Mr. Engineer intends to reach his home in the shortest possible time and acts completely intelligently to achieve this goal, what is the mathematical expectation of the number of days it will take for him to return home.
entrance In the first line, enter two natural numbers n n, the number of cities, and m m is the number of roads.
each of m m The next line contains three natural numbers u u and v v and p p means there is a two-way road with the possibility of being blocked p / 1000 p/1000 between two cities u u and v v is
It is guaranteed that the graph of given cities is connected.
There is at most one road between any two cities and no city has its own road.
The probability of all roads being blocked is less than 1.
2 ≤ n ≤ 100
000 2≤n≤100 000 1 ≤ m ≤ 100
000 1≤m≤100 000 1 ≤ u , v ≤ n 1≤u,v≤n u ≠ v u =v 0 ≤ p ≤ 1
000 0≤p≤1000
output In the only output line of Omid Riazi, print the number of days that Mr. Engineer is on the way with exactly 3 decimal places.
Sub-issues Constraint score subproblem 15 The graph of cities is a tree. 2 55 n ≤ 1
500 n≤1 500 and maximum four roads are connected to each city 3 15 n ≤ 300 n≤300 4 25 without additional restrictions Example Sample entry 1 4 4 1 2 500 1 3 500 2 4 625 3 4 500 Plain text Sample output 1 3.556 Plain text Sample input 2 2 1 1 2 999 Plain text Sample output 2 1000.000 write in java
- Assistant