Under construction

Still being built. Things may change

Farm and Factory

Time limit5sMemory limit128 MB

Summary
Given a weighted graph with two special nodes, choose non-negative toll values for new edges from a virtual capital so every shortest path to farm and factory avoids it, minimizing average distance to all cities, expressed as an exact fraction.
Level

Hard9 of 10

Topics
Shortest path, Graph, Greedy, Math
Solved
No attempts yet

Problem

All hail Bitolomew, the king of Byteland!

King Bitolomew rules a small country. Every citizen except the king works at either the farm or the factory, which are located in two different cities, so every morning the residents of each city commute to those two cities.

The road network of Byteland consists of undirected roads, each joining a pair of distinct cities. Roads meet only at cities (bridges and tunnels are allowed), and several roads may directly connect the same pair of cities. Both the farm and the factory are reachable from every city.

Some time ago the king put a fixed toll on every road: each time a citizen travels along a road, they must pay that road's toll. Since then, every citizen commutes along a cheapest route, i.e. one whose total toll is minimum.

The king now wants to found a brand-new capital as one additional city. The capital must be connected to some of the existing cities by new direct roads so that every city is reachable from it. Each new road may be given any non-negative toll (not necessarily an integer).

The king wants to set the tolls of the new roads so that for every city vv other than the capital there exists a cheapest path from vv to the farm and a cheapest path from vv to the factory, neither of which passes through the capital (here vv may itself be the farm or the factory). Subject to this requirement, he wants to minimize the average, over all nn cities, of the cost of a cheapest path from the capital to that city.

Help the king determine this minimum possible average cost.

Input

The first line contains an integer TT, the number of test cases. The test cases follow.

Each test case begins with a line containing two integers nn and mm (2≤n≤1052 \le n \le 10^5, 1≤m≤3⋅1051 \le m \le 3\cdot10^5): the number of cities and the number of roads. Each of the next mm lines contains three integers uu, vv, cc (1≤u,v≤n1 \le u, v \le n, u≠vu \ne v, 0≤c≤1060 \le c \le 10^6): a road between cities uu and vv with toll cc. Several roads may connect the same pair of cities.

The farm is city 11 and the factory is city 22; both are reachable from every city.

Output

For each test case, print a single line with the minimum possible average cost.

The answer is always rational; print it as an irreducible fraction p/q in lowest terms with q≥1q \ge 1 (so gcd⁡(p,q)=1\gcd(p, q) = 1, and q=1q = 1 when the answer is an integer). For example, an answer of 116\tfrac{11}{6} is printed as 11/6, and an answer of 22 is printed as 2/1.

Examples3

  1. Example 1

    Input
    1
    3 3
    1 2 5
    2 3 5
    3 1 1
    
    Expected output
    11/6
    
  2. Example 2

    Input
    1
    2 1
    1 2 4
    
    Expected output
    2/1
    
  3. Example 3

    Input
    1
    3 3
    1 2 2
    2 3 2
    3 1 2
    
    Expected output
    1/1