#P6840. [BalkanOI 2009] year2012 - A New Beginning

[BalkanOI 2009] year2012 - A New Beginning

Description

An extreme solar flare heated up the Earth and caused a huge disaster. Crust plates are freely floating in the mantle; earthquakes of unknown magnitude are making megacities collapse; mountains are being flooded by gigantic tsunamis; countries are turning into oceans of lava and volcanic ash.

It is now December 21, 2012, and your only chance to save yourself and your family from the end of the world is to board the government ship on the Himalayas, a modern ark to save humanity. You have an airplane that flies at a constant speed and a map with all fixed airports. Unfortunately, not all airports are connected—huge volcanic ash clouds block some routes, and other airports are too far apart. Also, not all airports have fuel supply—some airports have nothing left but bare runways—and you cannot refuel there. Since all navigation methods have been destroyed, the only possible path between two airports is the shortest one. Most importantly, due to atmospheric instability and sharp changes in air density, the engine’s fuel efficiency may differ during flight. Therefore, the fuel consumption also differs. The good news is that you know which pairs of airports you can fly between, how much fuel each flight needs, and where you can refuel. All you need to do is find a way to reach the Himalayas airport as fast as possible. Write a program year2012 that, given the coordinates of each airport, whether it has fuel, the plane’s fuel tank capacity, the plane’s speed, several pairs of airports that have a possible connection, and the fuel needed for each flight, computes the minimum time needed to complete the mission.

Input Format

Read from standard input.

The first line contains four integers (translator’s note: the sample does not strictly follow this rule; for the exact constraints, it is recommended to refer to the “Hint” section) N,M,V,CN, M, V, C, representing the number of airports, the number of available routes, the constant speed of the airplane, and the fuel tank capacity.

The next NN lines each contain three real numbers Xi,Yi,ZiX_i, Y_i, Z_i and a boolean value RiR_i. The three real numbers are the 3D coordinates of airport ii. Ri=0R_i = 0 means you cannot refuel at this airport, and Ri=1R_i = 1 means you can refuel.

The next MM lines each contain three integers Ak,Bk,FkA_k, B_k, F_k, describing a route between two airports and the fuel needed. Each route is bidirectional.

The last line contains two integers S,TS, T, representing the first and the last airport of the trip.

Output Format

Write to standard output.

Output one line with one real number, the minimum time from SS to TT. If the absolute error of your answer compared with the standard answer is at most 10410^{-4}, it will be considered correct.

If you cannot reach the destination, output 00.

6 9 2.5 9
0.0 5.0 0.0 1
0.0 0.0 -5.0 0
0.0 -5.0 0.0 0
0.0 0.0 5.0 0
3.0 4.0 0.0 0
4.0 3.0 0.0 1
1 2 5
2 3 8
1 4 5
4 3 5
1 5 1
5 6 9
5 2 1
2 6 2
6 4 4
1 3
12.5663706144

Hint

Constraints

  • Number of airports N[2,103]ZN \in \left[2, 10^3\right] \cap \Z.
  • Number of available routes M[1,104]ZM \in \left[1, 10^4\right] \cap \Z.
  • Constant plane speed V[1,103]V \in \left[1, 10^3\right] is a real number with at most 33 digits after the decimal point.
  • Fuel tank capacity C[1,103]ZC \in \left[1, 10^3\right] \cap \Z.
  • Airport coordinates Xi,Yi,Zi[100,100]X_i, Y_i, Z_i \in \left[-100, 100\right] are real numbers with at most 1818 digits after the decimal point. Also, it is guaranteed that Xi2+Yi2+Zi2X_i^2 + Y_i^2 + Z_i^2 is the same for all ii. In other words, for one testdata, all airports have the same distance to the Earth’s center.
  • Number of airports where you can refuel [1,20]Z\in \left[1, 20\right] \cap \Z.
  • The Earth radius is an integer not less than 11.
  • Route endpoints Ak,Bk[1,N]ZA_k, B_k \in \left[1, N\right] \cap \Z and AkBkA_k \ne B_k. Each route appears at most once.
  • Fuel cost of a route Fk[1,C]ZF_k \in \left[1, C\right] \cap \Z.

Notes

  • The distance of a route is the shortest arc on the sphere. There may be multiple such arcs, but we only care about the distance.
  • All route distances are at least 10610^{-6}.
  • Due to possible precision errors in floating-point computations, the distance from an airport to the Earth’s center may differ slightly. However, the testdata guarantees that the absolute error of all distances is at most 101010^{-10}, so the correctness of the algorithm is not affected.
  • Rs=1R_s = 1, which means the plane’s tank is full at the beginning. Each time you pass through an airport where you can refuel, the tank will be filled up again.
  • Landing, refueling, takeoff, and acceleration can be ignored, i.e. treated as 00.
  • All available routes are independent from each other. This means that if there is a route from AA to BB passing by CC, it does not imply that there is an available route from AA to CC, or from BB to CC.

Subtasks

For 40%40\% of the data, N8N \le 8.


Sample Explanation

The Earth radius is 55. The plane speed is 2.52.5, and the fuel tank capacity is 99. We want to go from 11 to 33. In the figure, black solid lines are available routes, airport indices are inside rectangles, and fuel costs are labeled next to the black lines. Airports where you can refuel are hollow points. Clearly, we cannot directly use 1231 \rightarrow 2 \rightarrow 3 or 1431 \rightarrow 4 \rightarrow 3—their fuel costs are 1313 and 1010, which exceed the tank capacity. In fact, all routes cost more than 99 fuel, so we must pass through airport 66. We have three possible routes: 1261 \rightarrow 2 \rightarrow 6, 1461 \rightarrow 4 \rightarrow 6, and 15261 \rightarrow 5 \rightarrow 2 \rightarrow 6. The first two are obviously the shortest (routes 121 \rightarrow 2, 525 \rightarrow 2, 262 \rightarrow 6, 141 \rightarrow 4, and 464 \rightarrow 6 take the same amount of time). After we refuel to full at airport 66, if we go to airport 22, we still cannot reach the destination—we are short of one unit of fuel. One feasible route is to go through 44, and then use up all fuel to reach 33. Finally, the routes we can choose are $1 \rightarrow 2 \rightarrow 6 \rightarrow 4 \rightarrow 3$ and $1 \rightarrow 4 \rightarrow 6 \rightarrow 4 \rightarrow 3$. Both have four right-angle turns, so their total lengths are equal, both equal to the circumference of the Earth’s equator, i.e. 2πR2 \pi R. Therefore, the time cost is $\dfrac{2 \pi R}{V} \approx 12.566370614359172953850573533118$.

Translated by ChatGPT 5