This page is still under construction.

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

Difficult Routes

Time limit1sMemory limit128 MB

Summary
Given a 3D road map where each directed edge has a difficulty, find the shortest route from s to t whose maximum edge difficulty equals exactly d.
Level

Medium7 of 10

Topics
Graph, Shortest path, Binary search, Greedy
Solved
No attempts yet

Problem

In preparation for the coming Olympics, you have been asked to propose bicycle training routes for your national cycling team. The training committee wants to identify routes between pairs of locations at several sites around the country. Each route must have a desired level of difficulty based on the steepness of its hills.

You are given a road map with elevation data superimposed on it. Each intersection, where two or more roads meet, is identified by its xx-, yy-, and zz-coordinates. Each road starts and ends at an intersection, is straight, and does not contain bridges over or tunnels under other roads. A road may be cycled in either direction, and its difficulty depends on the direction of travel.

The difficulty level dd of cycling a road is 00 if the road is level or is travelled in the downhill direction. The difficulty of a non-level road travelled in the uphill direction is ⌊100⋅rise/run⌋\lfloor 100 \cdot \text{rise} / \text{run} \rfloor, where rise is the absolute change in elevation and run is the distance between its two endpoints in their horizontal projection onto the plane at elevation zero. (Cycling a descending road always has difficulty 00.)

The length of a road is the straight-line (3D Euclidean) distance between its two endpoints. A route is a sequence of roads in which each road continues from the intersection where the previous road ended; the length of a route is the sum of the lengths of its roads. A route has difficulty dd if the maximum difficulty among all of its roads equals dd. For a chosen pair of locations, the committee wants the route with the required difficulty that has the shortest possible total length.

Reminder: the floor function ⌊X⌋\lfloor X \rfloor means XX truncated to an integer.

The figure below shows a road map with three intersections, corresponding to the sample input.

The edge labels on the darker shaded surface give the uphill difficulty levels. The lighter shaded surface is the horizontal projection onto the plane at elevation zero.

Input

The input consists of several road maps. Each map begins with two non-negative integers NN and MM on a line by themselves, separated by a space, giving the number of intersections and the number of roads, respectively (0<N,M≤100000 < N, M \le 10000). A line containing N=0N = 0 and M=0M = 0 marks the end of the input.

Each of the next NN lines contains three integers, separated by single spaces, giving the xx-, yy-, and zz-coordinates of an intersection. Each coordinate is between 00 and 1000010000, inclusive. Intersections are numbered starting from 11 in the order they appear. Each of the following MM lines contains two integers, the two endpoint intersections of a road (a road may be cycled in either direction).

Finally, a line with three integers ss, tt, and dd gives the desired start intersection ss, finish intersection tt, and required difficulty level dd for the training route (0≤d≤100 \le d \le 10). A valid training route must contain at least one road of difficulty exactly dd and no road of difficulty greater than dd. If the route is a closed circuit, then ss and tt are the same intersection.

Output

For each road map, print a single line containing either:

  1. the shortest length of a valid training route, rounded to exactly three decimal places (always printing all three decimal digits); or
  2. the single word None if no feasible route exists.

Hint

Reminder — how to round a positive number of the form R.xxxy to three decimal places:

  • If the fourth decimal digit y is less than 5, the result is R.xxx.
  • Otherwise, the result is R.xxx + 0.001.

For example, 10.3463 is printed as 10.346, and 10.3695 is printed as 10.370.

Examples1

  1. Example 1

    Input
    3 3
    0 0 0
    100 100 6
    200 0 7
    1 2
    2 3
    3 1
    1 2 3
    3 3
    0 0 0
    100 100 6
    200 0 7
    1 2
    2 3
    3 1
    1 1 4
    3 3
    0 0 0
    100 100 6
    200 0 7
    1 2
    2 3
    3 1
    2 1 5
    0 0
    
    Expected output
    341.547
    283.097
    None