Find the shortest tunnel between two circular islands whose entrance points sit at least 100 cm inside the rims, so that the reachability graph over islands becomes strongly connected.
Hard8GraphGeometryUnion-findBinary searchNo attempts yetTime limit5sMemory limit512 MBWeenesia is an archipelago in the plane. Every island is a perfectly circular disk, its boundary included, and no two islands overlap or touch. Palm trees grow straight up on some islands, so a palm tree is a point of the plane together with a height.
A courier has to be able to carry an object from any land point to any other land point. Moving inside one island is always possible. A courier standing on an island can also climb a palm tree of height h on that island and throw the object to any land point whose distance from the palm tree is at most k×h, possibly on a different island. A throw needs a palm tree to start from, so it works in one direction only.
Throws alone may not be enough, so you may dig one tunnel between two different islands. The tunnel joins one point of one island to one point of another island and passes under the sea and under any island in between. A courier walks through a tunnel in both directions. To keep the sea out, each of the two tunnel entrances must be at least 1 metre (100 centimetres) away from the sea, so an entrance on an island of radius r lies within distance r−100 of the centre of that island. The length of the tunnel is the distance between its two entrances.
Find the length of the shortest tunnel that makes the courier system work.
The first line contains three integers n, m and k (1≤n≤5000, 0≤m≤10000, 1≤k≤1000): the number of islands, the number of palm trees, and the ratio between the throwing range and the palm height.
Each of the next n lines contains three integers x, y and r (∣x∣,∣y∣≤106, 100≤r≤106): the centre and the radius of an island, in centimetres.
Each of the next m lines contains three integers x, y and h (∣x∣,∣y∣≤106, 1≤h≤104): the position and the height of a palm tree, in centimetres.
No two islands intersect. Every palm tree stands strictly inside an island. No two palm trees stand at the same point.
If the courier system already works without a tunnel, print 0.000000. If no single tunnel makes it work, print impossible. Otherwise print the length of the shortest such tunnel in centimetres.
Print the number with exactly six digits after the decimal point.