PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BF0000053. Con đường trên trời (Heavenly Road)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Con đường trên trời (Heavenly Road)

Heavenly Road

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN attractions and MM directed railway routes. Every route u→vu\to v has fun value VV and positive fare PP. Find the maximum sum-of-fun divided by sum-of-fares among directed cycles, or print -1 if none exists.

Input

First line N,MN,M; then MM lines u,v,V,Pu,v,V,P.

Output

Print -1 if there is no directed cycle; otherwise the maximum ratio rounded to one decimal place.

Subtasks

  • Subtask 1 (20 points): 2≤N≤1002\le N\le100, 1≤M≤201\le M\le20; 1≤u,v≤N1\le u,v\le N; 1≤V,P≤10001\le V,P\le1000; parallel directed edges allowed; finite answer at most 200200.
  • Subtask 2 (30 points): 2≤N≤30002\le N\le3000, 1≤M≤20001\le M\le2000; 1≤u,v≤N1\le u,v\le N; 1≤V,P≤10001\le V,P\le1000; parallel directed edges allowed; finite answer at most 200200.
  • Subtask 3 (50 points): 2≤N≤70002\le N\le7000, 1≤M≤200001\le M\le20000; 1≤u,v≤N1\le u,v\le N; 1≤V,P≤10001\le V,P\le1000; parallel directed edges allowed; finite answer at most 200200.

Examples

Input

3 3
1 2 7 2
2 3 9 3
3 1 8 3

Output

3.0

Explanation

The only cycle is 1→2→3→11\to2\to3\to1. It has total fun 7+9+8=247+9+8=24 and total expense 2+3+3=82+3+3=8, giving ratio 24/8=324/8=3. Rounded to one decimal, the output is 3.0.