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

#BS0000405. Đường đi đẹp nhất (Beautiful Path)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đường đi đẹp nhất (Beautiful Path)

Beautiful Path

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A directed graph has nn vertices numbered 1 through nn and mm edges. Edge ii runs from uiu_i to viv_i (ui<viu_i<v_i), with positive integer beauty bib_i and cost cic_i. Parallel edges are allowed. Choose a path from 1 to nn and divide its total beauty by its total cost. Find the greatest achievable ratio; at least one such path exists.

Input

The first line contains integers n,mn,m. Each of the next mm lines contains ui,vi,bi,ciu_i,v_i,b_i,c_i, the tail, head, beauty and cost of edge ii, in order.

Output

Print the maximum ratio as a real number. The absolute or relative error must not exceed 10−910^{-9}.

Subtasks

  • Subtask 1 (20 points): 2≤n≤152\le n\le 15; 1≤m≤301\le m\le 30; 1≤ui<vi≤n1\le u_i<v_i\le n; 1≤bi≤1041\le b_i\le10^4; 1≤ci≤101\le c_i\le 10; for every 1≤i≤m1\le i\le m. A path from 1 to nn exists.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le 2000; 1≤m≤40001\le m\le 4000; 1≤ui<vi≤n1\le u_i<v_i\le n; 1≤bi≤1041\le b_i\le10^4; 1≤ci≤101\le c_i\le 10; for every 1≤i≤m1\le i\le m. A path from 1 to nn exists.
  • Subtask 3 (50 points): 2≤n≤2000002\le n\le 200000; 1≤m≤2000001\le m\le 200000; 1≤ui<vi≤n1\le u_i<v_i\le n; 1≤bi≤1041\le b_i\le10^4; 1≤ci≤100001\le c_i\le 10000; for every 1≤i≤m1\le i\le m. A path from 1 to nn exists.

Examples

Input

3 3
1 2 2 1
2 3 4 3
1 3 2 3

Output

1.500000000000

Explanation

The path 1→2→31\to2\to3 has beauty 2+4=62+4=6, cost 1+3=41+3=4, ratio 1.51.5. The direct path has ratio 2/32/3. Thus the maximum is 1.51.5.