I like Dijkstra more than Bellman-Ford... But what should I do if I like BFS even more than Dijkstra?
Generally, in an undirected graph with weighted edges, the shortest path refers to the path with the minimum sum of edge weights. However, Jaewon, who loves BFS too much, wants to minimize the number of edges included in the path.
We define any path that minimizes the number of edges to be "Lemon Path". The weight of a Lemon Path is defined as the sum of the weights of the edges included in that path, and the "Lemon Distance" between two vertices is defined to be the average of the weights of all Lemon Paths connecting two vertices.
A connected graph with vertices and bidirectional edges is given. The -th edge connects and , and its weight is .
Find the Lemon Distance between vertex and all other vertices. The graph may contain self-loops or multiple edges.
The input is given in the following format.
From the first line, print the Lemon Distance between vertex and vertex on the -th line over lines, using the following method.
If the Lemon Distance is where and are coprime positive integers, print a positive integer such that and . Also, it is guaranteed that the number of Lemon Paths between vertex and other vertex is never a multiple of .
The given graph can be represented as the figure above. For each vertex, the Lemon Distance is calculated as follows.
| 5 | 37 | No additional constraints. |