Under construction

Still being built. Things may change

Galaxy Quest

Time limit5sMemory limit1024 MB

Summary
For each query, find the least fuel needed to fly from planet 1 to a target planet within a time limit, where each highway's fuel cost depends on how long the trip takes.
Level

Hard8 of 10

Topics
Shortest path, Dynamic programming, Geometry
Solved
No attempts yet

Statement

You are travelling through the galaxy in your spaceship. There are nn planets, numbered from 11 to nn, and each planet is modelled as a point in 3-dimensional space.

You can travel between these planets along mm space highways. Each highway follows the straight line that connects its two planets. Your engine can accelerate (or decelerate) at 1m/s21\text{m/s}^2, and it uses 1 litre of fuel per second. There is no limit to how fast you can go, but you must come to a complete standstill each time you arrive at the planet at the end of a highway.

A highway may pass through planets other than the two it connects. Your ship has hyperspace technology, so it phases through those planets without stopping. You cannot switch from one highway to another midway, so every highway must be travelled in full.

Figure G.1: Illustration of the first sample input. Highways are drawn in blue, and the route from planet 1 to planet 3 is shown. The green start of a highway marks acceleration, and the red end marks deceleration. The figure shows the optimal route for the second mission.

You need to fly several missions. In each mission you start at your home planet (planet 1) and must reach a given target planet within a given time limit. For each mission, determine whether it can be completed, and if so, find the least amount of fuel required.

Input

The first line contains three integers nn, mm, and qq (1≤n,m,q≤1051 \le n,m,q \le 10^5, n≥2n \ge 2), where nn is the number of planets, mm is the number of highways, and qq is the number of missions.

The next nn lines each contain the coordinates xix_i, yiy_i, and ziz_i of planet ii, in metres (∣xi∣,∣yi∣,∣zi∣≤103|x_i|,|y_i|,|z_i| \le 10^3, 1≤i≤n1 \le i \le n).

The next mm lines each contain two integers aa and bb (1≤a,b≤n1 \le a,b \le n, a≠ba \neq b), describing a highway that connects planets aa and bb. A highway can be traversed in either direction.

The last qq lines each contain a target planet cc and a time limit tt in seconds (2≤c≤n2 \le c \le n, 1≤t≤1031 \le t \le 10^3).

All planets are at distinct locations. No two highways connect the same pair of planets. For each mission, both the absolute and the relative difference between the time limit and the shortest possible completion time are at least 10−610^{-6}.

Output

For each mission, print the least amount of fuel in litres needed to reach the target planet within the time limit. If the target cannot be reached in time, print impossible. Answers are accepted with an absolute or relative error of at most 10−610^{-6}.

Examples2

  1. Example 1

    Input
    4 4 3
    -30 0 0
    0 0 0
    50 0 0
    -30 10 0
    1 2
    2 3
    3 4
    4 1
    2 10
    3 25
    4 7
    
    Expected output
    impossible
    19.0538441903
    4.0000000000
    
  2. Example 2

    Input
    4 2 5
    -3 0 2
    7 -9 -3
    4 4 -6
    8 -1 8
    1 2
    2 3
    2 1000
    2 100
    3 1000
    3 100
    4 1000
    
    Expected output
    0.0287058122
    0.2874671888
    0.1120998619
    1.1272896971
    impossible