Particle Swapping
Time limit5sMemory limit256 MB
For each queried start pair, swap two tokens along graph edges one move at a time so their closest approach stays as large as possible.
- Level
Hard8 of 10
- Topics
- Minimum spanning tree, Graph, Binary search, Union-find
- Solved
- No attempts yet
Problem
A research team is preparing an experiment in particle physics. On a flat plate they have built a system of nodes joined by wires. The wires may cross each other on the plate.
When the experiment starts, a pair of particles appears at two different nodes. One ordinary matter particle appears at node , and the matching antimatter particle appears at node . The goal is to swap the two particles, that is, to reach the state where the matter particle is at node and the antiparticle is at node . The experiment runs as a sequence of moves. One move sends one of the two particles from the node it occupies to a neighbouring node along a wire.
Matter and antimatter annihilate when they get too close, which destroys the whole experiment. The team therefore wants a swap in which the smallest Euclidean distance between the two particles is as large as possible. That smallest distance is the safeness of the experiment. While a particle travels along a wire its position does not count, so the only risky moments are the moments when both particles are at nodes.
The physicists do not know yet where the particles will appear. They have written down candidate pairs of starting nodes , and for each candidate they want the largest safeness they can achieve.
Input
The first line contains an integer (), the number of nodes. Each of the next lines contains two integers and (), the coordinates of one node on the plate, given in order from node 1 to node . No two nodes are at the same point.
The next line contains an integer (), the number of wires. Each of the next lines contains two integers and (, ), meaning that a wire joins node and node . At most one wire joins any two nodes, and no wire joins a node to itself.
The next line contains an integer (), the length of the candidate list. Each of the next lines contains two integers and (, ), the indices of the starting nodes and . Every listed pair admits a swap with positive safeness, so the two particles never have to occupy the same node.
Output
Print lines. Line holds the largest safeness achievable for the -th pair on the list, written with exactly 8 digits after the decimal point and rounded to the nearest value at that precision. Every achievable safeness is the distance between two nodes, so each answer is the square root of an integer.