eolymp
bolt
Try our new interface for solving problems
Problems

Difficult Routes

Difficult Routes

In preparation for the coming Olympics, you have been asked to propose bicycle training routes for your country's team. The training committee wants to identify routes for traveling between pairs of locations in multiple sites around the country. Each route must have a desired level of difficulty based on the steepness of its hills. \includegraphics{https://static.e-olymp.com/content/fa/fa36e5d50c7e048b74f942dd78208200aa533ea6.jpg} \includegraphics{https://static.e-olymp.com/content/29/2997696d35db62b4892007e26b2ee4ba10c0580b.jpg} You will be given a road map with the elevation data superimposed upon it. Each intersection, where two or more roads meet, is identified by its \textbf{x}-, \textbf{y}-, and \textbf{z}-coordinates. Each road starts and ends at an intersection, is straight, and does not contain bridges over or tunnels under other roads. The difficulty level, \textbf{d}, of cycling a road is \textbf{0} if the road is level or travelled in the downhill direction. The difficulty of a non-level road when travelled in the uphill direction is \textbf{100*rise/run} . Here \textbf{rise} is the absolute value of change in elevation and \textbf{run} is the distance between its two intersection points in its horizontal projection to the \textbf{2}D-plane at elevation zero. Note that the level of difficulty for cycling a descending road is zero. A route, which is a sequence of roads such that a successor road continues from the same intersection where its predecessor road finishes, has a level of difficulty \textbf{d} if the maximum level of difficulty for cycling among all its roads equals \textbf{d}. The committee is also interested in the chosen route between two selected locations, if such a route with the desired difficulty level exists, being the one with the shortest possible distance to travel. \includegraphics{https://static.e-olymp.com/content/fa/fa36e5d50c7e048b74f942dd78208200aa533ea6.jpg} \includegraphics{https://static.e-olymp.com/content/29/2997696d35db62b4892007e26b2ee4ba10c0580b.jpg} \textbf{Reminder}: The floor function \textbf{X} means \textbf{X} truncated to an integer. The figure shows a road map with three intersections for the three sample inputs. \includegraphics{https://static.e-olymp.com/content/c5/c5dfa1c1f9d033da436dd5153c04bd286993fa9d.jpg} The edge labels of the darker shaded surface give the level of difficulty of going up hill. The lighter shaded surface is the horizontal projection to the \textbf{2}D-plane at elevation zero. \InputFile Input consists of many road maps. Each map description begins with two non-negative integers \textbf{N} and \textbf{M}, separated by a space on a line by themselves, that represent the number of intersections and the number of roads, respectively. \textbf{0} < \textbf{N}, \textbf{M} ≤ \textbf{10000}. A value of both N and M equal to zero denotes the end of input data. Each of the next \textbf{N} lines contains three integers, separated by single spaces, which represent the \textbf{x}-, \textbf{y}- and \textbf{z}-coordinates of an intersection. The integers have values between \textbf{0} and \textbf{10000}, inclusive. Intersections are numbered in order of their appearance starting with the value one. Each of the following \textbf{M} lines contains two integers that represent start and end intersections of a road. Finally, three integers \textbf{s}, \textbf{t} and \textbf{d} that represents the desired starting intersection number \textbf{s}, the finishing intersection number \textbf{t} and the level of difficulty \textbf{d} for a training route are given on line by themselves. A valid training route must have at least one road with a difficulty level of \textbf{d}, and no road with a difficulty level greater than \textbf{d}. \textbf{0} ≤ \textbf{d ≤ 10}. If the training route is meant to form a closed circuit, then \textbf{s} and \textbf{t} are the same intersection numbers. \OutputFile For each road map and desired route, the output consists of a single line that contains: \begin{enumerate} \item number denoting the shortest length of a training route rounded to one decimal places, or \item the single word "\textbf{None}" if no feasible route exists. \end{enumerate} \textbf{Reminder: Rounding a positive number R.xxxy to three decimal places} \begin{itemize} \item If the fourth decimal place is less than \textbf{5}, then the rounded value is \textbf{R.xxx} \item Otherwise, the rounded value is \textbf{R.xxx + 0.001} \end{itemize} Examples are: for the value of \textbf{10.3463} the output should be \textbf{10.346}, and for the value of \textbf{10.3695} the output is either \textbf{10.37} or \textbf{10.370} Reminder: Rounding a positive number R.xxxy to three decimal places • If the fourth decimal place is less than 5, then the rounded value is R.xxx • Otherwise, the rounded value is R.xxx + 0.001 Examples are: for the value of 10.3463 the output should be 10.346, and for the value of 10.3695 the output is either 10.37 or 10.370
Time limit 2 seconds
Memory limit 32 MiB
Input example #1
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
Output example #1
341.547
283.097
None
Source The 2011 South Pacific Programming Contest