题目收集
题目列表题单
返回列表

Hunt

CodeforcesP0016· ZJU Summer 2026 Contest 1原题链接
dp图论

创建于 2026/07/16 · 更新于 2026/07/16

题目描述

There is a directed graph with nnn vertices numbered from 111 to nnn and mmm directed edges. You start at vertex SSS and want to reach vertex TTT. The graph is strongly connected.

For each 1≤i≤n1 \le i \le n1≤i≤n, vertex iii has a height hih_ihi​. For each 1≤i≤m1 \le i \le m1≤i≤m, the iii-th directed edge has a start vertex uiu_iui​, an end vertex viv_ivi​, and a length did_idi​. The time to traverse an edge from uuu to vvv is Cd(1+(hu−hvd)2)+G(hu2+hv2)C d \left(1 + \left(\dfrac{h_u - h_v}{d}\right)^2\right) + G (h_u^2 + h_v^2)Cd(1+(dhu​−hv​​)2)+G(hu2​+hv2​), where CCC and GGG are given constants.

You have a special item that can be used on at most KKK edges. When used on an edge, the traversal time for that edge is divided by α\alphaα. That is, the time becomes 1α(Cd(1+(hu−hvd)2)+G(hu2+hv2))\dfrac{1}{\alpha}\left(C d \left(1 + \left(\dfrac{h_u - h_v}{d}\right)^2\right) + G (h_u^2 + h_v^2)\right)α1​(Cd(1+(dhu​−hv​​)2)+G(hu2​+hv2​)), where α≥1\alpha \ge 1α≥1 is a given constant. You can also issue a secret command to change the height of at most one vertex to any real number. However, if your path passes through this vertex (i.e., it is an intermediate vertex on the path), the lengths of the edges immediately before and after it must be equal.

Find the minimum time required to reach vertex TTT from vertex SSS.

输入格式

The first line of the input contains two integers ccc and ttt, representing the test case number and the number of test cases. For the samples, ccc indicates that the sample has the same constraints as test case ccc.

Then, for each test case:

  • The first line contains eight integers n,m,S,T,C,G,K,αn, m, S, T, C, G, K, \alphan,m,S,T,C,G,K,α, representing the number of vertices, the number of edges, the starting vertex, the target vertex, the constant CCC, the constant GGG, the maximum number of times the special item can be used, and the acceleration constant α\alphaα.

  • The next line contains nnn integers, the iii-th of which is hih_ihi​, representing the current height of vertex iii.

  • The next mmm lines each contain three integers u,v,du, v, du,v,d, representing the start vertex, end vertex, and length of an edge.

For all test cases, 1≤n,m,∑n≤25000,∑m≤30000,0≤hi,C,G,α,d≤1000000,0≤K≤200,d≥1,α≥1,1≤u,v,S,T≤n,u≠v,S≠T1 \le n, m, \sum n \le 25000, \sum m \le 30000, 0 \le h_i, C, G, \alpha, d \le 1000000, 0 \le K \le 200, d \ge 1, \alpha \ge 1, 1 \le u, v, S, T \le n, u \not = v, S \not = T1≤n,m,∑n≤25000,∑m≤30000,0≤hi​,C,G,α,d≤1000000,0≤K≤200,d≥1,α≥1,1≤u,v,S,T≤n,u=v,S=T.

It is guaranteed that for any vertex ttt, there is at least one simple path from SSS to TTT.

输出格式

For each test case, output a single floating-point number on a single line, representing the answer. If the given answer is ansansans and your answer is resresres, your answer is considered correct if ∣ans−res∣max⁡(1,ans)≤10−8\frac{|\text{ans} - res|}{\max(1, \text{ans})} \le 10^{-8}max(1,ans)∣ans−res∣​≤10−8.

样例输入 #1

3 1
4 2 2 4 5 4 1 2
5 5 7 4
1 4 9
2 1 5

样例输出 #1

249.7777777778