National Olympiad in Informatics, China, 2012
The summer holidays are here, and little Z feels too bored at home. So, he decided to go alone to the amusement park. Upon entering, little Z took a look at the map. He noticed that the entire amusement park can be represented as a connected, undirected graph made up of attractions and trails joining them. Also, the graph contains at most one cycle (thus, can either be or ). Little Z's current location (the entrance) also happens to be an attraction. Little Z doesn't know which attractions are fun, so he decided to start from his current location and at each step afterwards, travel to another attraction which is connected to the current attraction by a trail. Furthermore, the same attraction (including the entrance attraction) should not be visited twice. Playful little Z will continue to play and play until the current attraction he's at and all of its adjacent attractions have been visited.
The sequence of attractions little Z visits can be interpreted as a simple path. He wants to know, what is the expected length of this path?
Little Z brought home the map of the amusement park, but forgot which attraction is the entrance. He can only assume that any of the attractions may be the entrance, where every attraction has equal probability to be the entrance. At the same time, every time he selects the next attraction to visit, all of the adjacent, unvisited attractions will have equal probability of being selected.
Input Specification
The first line of input consists of two integers and ,
respectively representing the number of attractions and trails.
For the following lines, each line will contain three integers
, , and , indicating that the -th trail connects
attractions and , and has a length of . All of the
attractions are numbered from to , and there will be at most one
trail between any two attractions.
Output Specification
Output a single line containing a single real number, the expected length of the path. Your answer will be considered correct if it differs from the correct answer by no more than .
Sample Input
4 3
1 2 3
2 3 1
3 4 4
Sample Output
6.00000000
Explanation
There are different paths in the sample input.
Path | Length | Probability |
---|---|---|
Thus, the expected length .
Constraints
For of the test cases, .
Test Case | Remarks | ||
---|---|---|---|
The graph is guaranteed to be a linked list | |||
Only node has a degree larger than | |||
/ | |||
/ | |||
/ | |||
/ | |||
The number of nodes in the cycle | |||
The number of nodes in the cycle | |||
The number of nodes in the cycle | |||
The number of nodes in the cycle |
Problem translated to English by .
Comments