luogu#P4951. [USACO01OPEN] Earthquake

[USACO01OPEN] Earthquake

Problem Description

An earthquake destroyed John’s farm. Tough John decides to rebuild his home. John has rebuilt nn pastures, and now he wants to build some roads to connect them. After studying the terrain, John found that there are mm possible roads that can be built. Coincidentally, the cows have recently formed an engineering team specialized in repairing roads. However, the cows are very business-minded: if there is no profit, they will not do the job.

The cows care about the speed of making money, that is, the ratio of total profit to total construction time. John and the cows reach an agreement: the cows will build roads to make all pastures connected, and John will pay ff dollars. Each road has its own construction time and building cost. There may be multiple roads connecting the same pair of pastures. It is guaranteed that all pastures can be connected, but it is also possible that the sum of building costs of some set of roads exceeds ff.

Please help the cows choose which roads to repair so that the profit per unit time is maximized.

Input Format

The first line contains three integers n,m,fn,m,f.

Lines 22 to m+1m+1 describe the roads. The (i+1)(i+1)-th line gives the information of the ii-th road: four integers ui,vi,ci,tiu_i,v_i,c_i,t_i, where uiu_i and viv_i are the indices of the pastures this road connects, cic_i is the cost to build the road, and tit_i is the time required to build the road.

Output Format

The first line contains a floating-point number rounded to four decimal places, representing the maximum profit per unit time the cows can earn. If the cows cannot make any profit, output 0.0000.

5 5 100
1 2 20 5
1 3 20 5
1 4 20 5
1 5 20 5
2 3 23 1
1.0625

Hint

Explanation of Sample Input/Output 1

The cows can choose the last four roads to connect all pastures. Then the total time is 1616 and the total cost is 8383, so the profit per unit time is 1716=1.0625\dfrac{17}{16}=1.0625.

Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 1n4001 \leq n \leq 400, 1m100001 \leq m \leq 10000, 1f2×1091 \leq f \leq 2 \times 10^9.
  • 1ui,vin1 \leq u_i,v_i \leq n, 1ci,ti2×1091 \leq c_i,t_i \leq 2 \times 10^9.

Translated by ChatGPT 5