Given a weighted graph, there are vertices, numbered from to . Bruce wants to travel from vertex to vertex . Each time, Bruce will randomly pick up one edge which is connected to Bruce's current location, and move to the adjacent vertex. Bruce repeats this way until he arrives at vertex .
In Bruce's city, the length of a path is defined as the XOR sum of the path. XOR sum refers to the successive XOR operations of all edges' weights on the path. Bruce wants to get the expectation of XOR sum to travel to vertex . Could you please write a program to help him?
Input Specification
The first line contains two integers, () and (), which are the number of vertices and the number of edges.
Each of the following lines contains three non-negative integers, , , and (, ), representing the undirected edge between and with weight .
Notice: self-loop, i.e. , is possible. It is guaranteed that the graph is connected.
Output Specification
Output the expectation of XOR sum to decimal places.
Sample Input
2 2
1 1 2
1 2 3
Sample Output
2.333
Explanation
Bruce has probability from to with XOR sum of , probability with XOR sum , probability with XOR sum of , …. Thus, the expectation is , which is approximately .
Comments