The Great Drone Show
Time limit30sMemory limit512 MB
Drones rise and fall over k moves, and cables snap once stretched past their limit. For each queried pair, find the first move that disconnects them.
- Level
Hard8 of 10
- Topics
- Union-find, Graph, Sorting
- Solved
- No attempts yet
Problem
This year's Great Drone Show is planned to be a big success, provided nothing goes wrong and everyone follows the plan.
The plan is worked out in every detail. At the beginning, drones are parked on the ground. To describe their movement, we use standard Euclidean coordinates in three dimensions, where the ground is the plane . The starting position of the -th drone is .
To allow communication during the show, there are cables between pairs of drones. Initially the cables also lie on the ground, as straight segments connecting some pairs of drones. The cable network is connected: from every drone there is a sequence of cables to every other drone. To avoid tangling, no two segments cross (they can only share endpoints).
During the show, a sequence of moves is performed. Each move changes the height (the coordinate) of one drone. Each move is performed smoothly, and it starts only after the previous one ends. During a move, the distances between some drones may change, and the cables can stretch to some degree. Each cable has a maximal length. If its endpoint drones move farther apart than this value, the cable breaks.
The organizers expect some cables to break. However, some pairs of drones must stay able to communicate, directly or indirectly. Given critical pairs of drones, determine whether communication between a pair becomes impossible at some point during the show. If it does, determine the move that causes the connection loss.
Input
The first line contains the number of test cases (). Each test case has the following format.
The first line contains (). Each of the next lines contains two integers , (), the coordinates of the -th drone. No two drones share a starting location.
The next line contains (), the number of cables. Each of the next lines contains three integers , , (, ; ): the two connected drones and the maximal length of the cable. A pair of drones is connected by at most one cable. The length of each cable at its starting position is within its limit.
The next line contains (). Each of the next lines contains two integers , (, ): the moving drone and its change in height. A positive raises the drone, and a negative lowers it. You may assume that no drone ever goes below the ground, so all coordinates stay non-negative.
Finally, the next line contains (), the number of critical pairs. Each of the next lines contains two drone numbers , (, ).
Over all test cases, the sum of values does not exceed , and the sums of and of each do not exceed .
Output
For every test case, print integers on separate lines, one per critical pair, in input order. For each pair, print the number of the first move after which the two drones can no longer communicate. Moves are numbered from 1. If a pair stays connected through the whole show, print .