This page is still under construction.

Parts of this page are still being built. What you see may change.

A New Beginning

Time limit2sMemory limit128 MB

Summary
Find the fastest route through airport flight graph, refuelling at up to 20 airports within tank capacity, using great-circle distances.
Level

Medium7 of 10

Topics
Graph, Shortest path, Bit manipulation
Solved
No attempts yet

Problem

An extreme solar eruption has heated the Earth, causing a monstrous cataclysm. Tectonic plates are floating freely along the Earth's mantle; earthquakes with unseen magnitudes are causing metropolises to collapse to the ground; mountains are inundated by gigantic tsunamis; countries are turning to oceans of lava and volcanic dust.

It is 21 December 2012 and your only chance to save yourself and your family from the apocalypse is to reach the government ships in the Himalayas -- the modern arks that will save mankind. You have an airplane that flies with constant speed and a map with all standing airports. Unfortunately, not all pairs of airports are connected: enormous clouds of volcanic dust block some routes, while other airports are too far away from each other. Furthermore, not all airports have fuel available; some of them have nothing left but bare runways, and there you cannot refuel the aircraft. Since all means of navigation are destroyed, the only possible path between two airports is the shortest one (the great-circle arc on the sphere). On top of that, due to atmospheric instability and dramatic changes of air density, the fuel efficiency of the engines varies between flights, so the fuel consumption differs as well.

The good news is that you know between which airports it is possible to fly and how much fuel each flight costs, and also where you can refuel. All you have to do is find a way to get from your airport to the airport in the Himalayas as fast as possible. Write a program that computes the minimum amount of time required, given the coordinates of each airport and whether it has fuel, the fuel tank capacity of the airplane, the speed of the airplane, which pairs of airports are connected by a potential flight, and how much fuel each flight requires.

Input

The first line contains four integers NN, MM, VV, and CC: the number of airports, the number of pairs of connected airports, the constant speed of the aircraft, and the fuel tank capacity, respectively.

The next NN lines describe the airports. Airports are points in 3-dimensional space, all lying on the surface of the Earth whose center is at the origin (0,0,0)(0, 0, 0). The ii-th of these lines contains three real numbers and a Boolean XiX_i, YiY_i, ZiZ_i, and RiR_i: the coordinates of the ii-th airport and whether you can refuel there (Ri=1R_i = 1 means you can, Ri=0R_i = 0 means you cannot).

The next MM lines describe the potential flights. Each pair of connected airports is unordered, i.e. a flight from AA to BB has the same properties as a flight from BB to AA. The kk-th of these lines contains three integers AkA_k, BkB_k, and FkF_k, denoting a potential flight between airport AkA_k and airport BkB_k that requires FkF_k units of fuel (in either direction).

The last line contains two integers SS and TT: the first and the last airport in your route.

Output

Print the minimum time required to get from airport SS to airport TT, rounded to exactly 1010 digits after the decimal point, on a single line.

If no route can be found, print the integer 0 on a single line instead.

Constraints

  • 2≤N≤10002 \le N \le 1000 — number of airports. Integer.
  • 1≤M≤100001 \le M \le 10000 — number of possible flights. Integer.
  • 1≤V≤10001 \le V \le 1000 — airplane's constant speed. Real number with up to 33 digits after the decimal point.
  • 1≤C≤10001 \le C \le 1000 — fuel tank capacity of the airplane. Integer.
  • −100≤Xi,Yi,Zi≤100-100 \le X_i, Y_i, Z_i \le 100 — coordinates of the ii-th airport. Real numbers with up to 1818 digits after the decimal point. Moreover, Xi2+Yi2+Zi2X_i^2 + Y_i^2 + Z_i^2 is constant for all ii, i.e. all airports lie at the same distance from the Earth's center within a given test case.
  • The number of airports where you can refuel is between 11 and 2020, inclusive.
  • The Earth's radius is an integer ≥1\ge 1.
  • 1≤Ak,Bk≤N1 \le A_k, B_k \le N — airports in the kk-th potential flight. Different integers. Each unordered pair appears at most once in the input.
  • 1≤Fk≤C1 \le F_k \le C — amount of fuel used by the airplane on the kk-th flight. Integer.

Notes:

  • A direct flight between two airports follows the shortest arc on the sphere (the great-circle arc) connecting them. Even if more than one such arc exists, only the distance matters.
  • No potential flight is shorter than 10−610^{-6}.
  • Due to precision errors, the distance from the Earth's center may differ slightly between airports, but the absolute difference between that distance and the Earth's radius is at most 10−1010^{-10}; thus the correctness of an algorithm is unaffected if all airports are considered to lie exactly on the Earth's surface.
  • RS=1R_S = 1, i.e. the fuel tank is always full at the beginning. Also, each time you visit an airport with fuel, the tank is filled up again.
  • The time required for landing, refueling, taking off, and accelerating is negligibly small and considered to be 00.
  • Potential flights are completely independent. If the arc of a flight from AA to BB happens to pass through some airport CC, this does not imply a flight between AA and CC, nor between BB and CC.

Hint

Consider the following situation. The Earth's radius is 55, the airplane's speed is 2.52.5, and the fuel tank capacity is 99; you must get from airport 11 to airport 33. You can refuel at airports 11 and 66.

The direct routes 1→2→31 \to 2 \to 3 and 1→4→31 \to 4 \to 3 consume 1313 and 1010 units of fuel respectively, both exceeding the tank capacity of 99. In fact, every route from 11 to 33 without refueling needs more than 99 units, so your only option is to refuel at airport 66.

There are three routes to airport 66: 1→2→61 \to 2 \to 6, 1→4→61 \to 4 \to 6, and 1→5→2→61 \to 5 \to 2 \to 6; the first two are the shortest. After filling the tank at 66, going straight through 22 toward 33 leaves you exactly 11 unit short of fuel. The only way is through 44: you reach 33 with the tank empty, but you are saved.

The optimal routes are therefore 1→2→6→4→31 \to 2 \to 6 \to 4 \to 3 and 1→4→6→4→31 \to 4 \to 6 \to 4 \to 3. Both consist of four 90∘90^\circ arcs, so their total length equals the Earth's equator, 2πR2\pi R. Consequently, the required time is 2πR/V≈12.56637061442\pi R / V \approx 12.5663706144.

Examples5

  1. Example 1

    Input
    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
    
    Expected output
    12.5663706144
    
  2. Example 2

    Input
    2 1 1 10
    1 0 0 1
    0 1 0 0
    1 2 3
    1 2
    
    Expected output
    1.5707963268
    
  3. Example 3

    Input
    3 1 1 10
    1 0 0 1
    0 1 0 0
    0 0 1 0
    1 2 4
    1 3
    
    Expected output
    0
    
  4. Example 4

    Input
    3 2 1 8
    1 0 0 1
    0 1 0 0
    -1 0 0 0
    1 2 5
    2 3 5
    1 3
    
    Expected output
    0
    
  5. Example 5

    Input
    3 2 1 8
    1 0 0 1
    0 1 0 1
    -1 0 0 0
    1 2 5
    2 3 5
    1 3
    
    Expected output
    3.1415926536