This page is still under construction.

Parts of this page are still being built. What you see may change.

Maximum Mean Cycle

Time limit1sMemory limit128 MB

Summary
Find the directed cycle with the largest mean edge weight and print it as a reduced fraction.
Level

Hard8 of 10

Topics
Graph, Dynamic programming, Number theory
Solved
No attempts yet

Problem

You are given a directed graph with weighted edges. Find a cycle whose average edge weight is as large as possible. The average edge weight of a cycle is defined as (the sum of the weights of its edges) divided by (the number of its edges).

Input

The first line contains two integers nn and mm (2≤n≤1002 \le n \le 100, 2≤m≤1042 \le m \le 10^4), the number of vertices and the number of edges. Each of the next mm lines contains three integers aa, bb, cc (1≤a,b≤n1 \le a, b \le n, a≠ba \ne b, 0≤c≤1060 \le c \le 10^6), describing a directed edge from vertex aa to vertex bb with weight cc. Between any pair of vertices there is at most one edge in each direction.

Output

Print the maximum average edge weight over all cycles as a reduced fraction p/qp/q in lowest terms (gcd⁡(p,q)=1\gcd(p, q) = 1, q≥1q \ge 1). If the value is an integer vv, print it as v/1v/1. It is guaranteed that the graph always contains at least one cycle.

Examples3

  1. Example 1

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

    Input
    2 2
    1 2 7
    2 1 3
    
    Expected output
    5/1
    
  3. Example 3

    Input
    2 2
    1 2 1
    2 1 0
    
    Expected output
    1/2