#P4292. [WC2010] 重建计划

    ID: 5020 远端评测题 4000ms 250MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>2010点分治单调队列分治WC

[WC2010] 重建计划

Problem Description

Country X was heavily hit by an earthquake, which almost paralyzed nationwide transportation, and the reconstruction plan is urgent. Country X consists of NN cities. The reconstruction team proposed that building only N−1N - 1 roads would make any two cities mutually reachable. Thus, they quickly proposed a plan containing N−1N - 1 roads that ensures pairwise reachability between cities, and they also evaluated the value v(e)v(e) that each road ee 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 kk, with L≤k≤UL \leq k \leq U, i.e., no fewer than LL roads and no more than UU roads. Meanwhile, to maximize utilization, the selected roads must form exactly one simple path, i.e., the kk 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 1≤i<k1 \leq i < k we have (qi=pi+1)(q_i = p_{i+1}).

The reconstruction team plans to modify their original plan to meet the requirement, that is, find a path SS among the original N−1N - 1 roads as the new plan, so that the average value of the new plan

AvgValue=∑e∈Sv(e)∣S∣AvgValue = \frac{\sum_{e \in S} v(e)}{|S|}

is maximized. Here v(e)v(e) denotes the value of road ee, and ∣S∣|S| is the number of roads in the new plan. Please help the reconstruction team find an optimal plan. Note: In this problem, LL and UU are set to guarantee a solution.

Input Format

The first line contains a positive integer NN, the number of cities in Country X.

The second line contains two positive integers L,UL, U, the lower and upper bounds on the number of roads to be built in the first-phase plan.

Each of the next N−1N - 1 lines describes the original plan of the reconstruction team, with three positive integers ai,bi,via_i, b_i, v_i, indicating a road (ai,bi)(a_i, b_i) whose value is viv_i. Cities are numbered 1⋯N1 \cdots N.

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 (3,1),(1,4)(3, 1), (1, 4) yields an average value of 2.52.5, which is the maximum average value.

For 20% of the testdata, N≤5000N \leq 5000.

For another 30% of the testdata, N≤100000N \leq 100000, and the original plan is exactly a path (chain).

For 100% of the testdata, N≤100000N \leq 100000, 1≤L≤U≤N−11 \leq L \leq U \leq N - 1, and vi≤106v_i \leq 10^6.

Translated by ChatGPT 5