#P12806. [AMPPZ 2019] The Great Drone Show
[AMPPZ 2019] The Great Drone Show
Description
This year’s Great Drone Show is going to be a stunning success! Well, if nothing goes horribly wrong. And if everybody sticks to the plan.
The plan is worked out in every detail. At the beginning, drones are parked on the ground. To describe their movement, we introduce standard Euclidean coordinates in three dimensions, in which the ground is the plane. The starting position of the -th drone is then described as .
To allow communication during the show, there are cables between pairs of drones. The cables initially also lie on the ground, in the form of straight segments connecting some pairs of drones. It is known that from every drone there is a sequence of cables to every other drone (the cable network is connected). Moreover, to avoid tangling the cables, no two segments cross each other (they can only have common endpoints).
During the show a sequence of moves will be performed. Every move consists of changing the height (i.e. the -coordinate) of one of the drones. Each move will be performed smoothly and will start only after the previous one ends. During a move, the distance between some drones may change – fortunately, the cables can stretch to some degree. For every cable we know the maximal length it can have – if its endpoint drones go further than this value, the cable breaks.
The show organizers are prepared for some cables to break. However, some pairs of drones must remain able to communicate, directly or indirectly. Given specific, critical pairs of drones, determine if communication between these pairs becomes impossible at some point during the show, and if so, determine the move which will cause the connection loss.
Input Format
The first line of input contains the number of test cases (). The test cases follow, each one in the following format:
- The first line contains the number of drones (). Each of the following lines contains two integers () – the and coordinates of the -th drone. No two drones occupy the same starting location.
- The next line contains an integer () – the number of cables. Each of the following lines describes a single cable, and contains three integers (; ) – the numbers of connected drones and its maximal length, respectively. A pair of drones can be connected by at most one cable. Every cable’s length at its starting position fits within the given length limit.
- The next line contains the number of moves (). Each of the following lines contain two integers (; ) – number of the moving drone and its change of height (positive if the drone raises, negative if it falls). You may assume that no drone ever falls below the ground (the coordinates remain non-negative).
- Finally, the following line contains an integer () – the number of critical pairs to be checked. In the next lines, these pairs are described – each one contains two drone numbers ().
The sum of values over all test cases does not exceed . Similarly, both the sum of values and the sum of values also do not exceed .
Output Format
For every test case, output in separate lines integers – the answers for each critical pair. For every such pair of drones, output the number of the first move after which the drones lost the ability to communicate. The moves are numbered starting from 1. If a critical pair remains connected during the whole show, output instead.
1
4
0 0
0 12
0 24
0 25
3
1 2 13
2 3 13
3 4 1
4
3 1
2 6
3 1
2 -6
4
1 2
2 3
3 4
1 4
2
-1
1
1
京公网安备 11011102002149号