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
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
For the following
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
Path | Length | Probability |
---|---|---|
Thus, the expected length
Constraints
For
Test Case | Remarks | ||
---|---|---|---|
The graph is guaranteed to be a linked list | |||
Only node | |||
/ | |||
/ | |||
/ | |||
/ | |||
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