#P4292. [WC2010] 重建计划
[WC2010] 重建计划
Description
Country X was heavily hit by an earthquake, which almost paralyzed nationwide transportation, and the reconstruction plan is urgent. Country X consists of cities. The reconstruction team proposed that building only roads would make any two cities mutually reachable. Thus, they quickly proposed a plan containing roads that ensures pairwise reachability between cities, and they also evaluated the value that each road would bring after construction.
Due to the complexity and difficulty of the reconstruction plan, and with limited funds, the government requires that the number of roads to be built in the first phase be , with , i.e., no fewer than roads and no more than roads. Meanwhile, to maximize utilization, the selected roads must form exactly one simple path, i.e., the roads can be arranged as a sequence $e_1 = (p_1, q_1), e_2 = (p_2, q_2), \cdots, e_k = (p_k, q_k)$ such that for we have .
The reconstruction team plans to modify their original plan to meet the requirement, that is, find a path among the original roads as the new plan, so that the average value of the new plan
is maximized. Here denotes the value of road , and is the number of roads in the new plan. Please help the reconstruction team find an optimal plan. Note: In this problem, and are set to guarantee a solution.
Input Format
The first line contains a positive integer , the number of cities in Country X.
The second line contains two positive integers , the lower and upper bounds on the number of roads to be built in the first-phase plan.
Each of the next lines describes the original plan of the reconstruction team, with three positive integers , indicating a road whose value is . Cities are numbered .
Output Format
Output a single line containing a real number AvgValue, the maximum average value.
Keep three digits after the decimal point.
4
2 3
1 2 1
1 3 2
1 4 3
2.500
Hint
In the new plan, selecting the path yields an average value of , which is the maximum average value.
For 20% of the testdata, .
For another 30% of the testdata, , and the original plan is exactly a path (chain).
For 100% of the testdata, , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号