Maximum Mean Cycle
Time limit1sMemory limit128 MB
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 and (, ), the number of vertices and the number of edges. Each of the next lines contains three integers , , (, , ), describing a directed edge from vertex to vertex with weight . 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 in lowest terms (, ). If the value is an integer , print it as . It is guaranteed that the graph always contains at least one cycle.