The course Mirko wins
Time limit3sMemory limit128 MB
Find the directed cycle where Mirko beats Slavko with the fewest roads, breaking ties by the largest time difference.
- Level
Medium7 of 10
- Topics
- Shortest path, Graph, Dynamic programming
- Solved
- No attempts yet
Problem
Mirko and Slavko are the only two contestants in the Dabrovina Donja Grand Prix. The race runs through nearby villages, and the villages are connected by one way roads. For road we know , the time Mirko needs to cross it, and , the time Slavko needs.
A course starts in some village and returns to that same village. Mirko's time on a course is the sum of over its roads, and Slavko's time is the sum of . Mirko wins the course when his time is smaller than Slavko's, and the difference between the two times is Mirko's advantage.
The course is not decided yet. Mirko has bribed the organisers, so they will pick a course that Mirko wins with as few roads as possible. If several courses use that number of roads, the organisers pick one where Mirko's advantage is largest.
Input
The first line contains two integers and , the number of villages and the number of roads. (, )
Each of the next lines contains four integers , , , describing one road. (, , ) The road runs one way from village to village , Mirko needs time to cross it and Slavko needs . No two roads connect the same pair of villages in the same direction.
At least one course that Mirko wins exists.
Output
Print, on one line separated by a space, the number of roads on the course the organisers pick and Mirko's advantage on that course.