Quintiq Puzzle Competition Playground

Start

2018-06-18 08:00 UTC

Quintiq Puzzle Competition Playground

End

2018-06-25 08:00 UTC
The end is near!
Contest is over.
Not yet started.
Contest is starting in -341 days 14:51:22

Time elapsed

168:00:00

Time remaining

0:00:00

Problem B
Bearly Made It

/problems/bearlymadeit/file/statement/en/img-0001.jpg

Barney the polar has wandered off on an adventure. Lost in thought, he suddenly realizes he has strayed too far from his mother and is stuck on an ice shelf. He can still see her in the distance, but the only way back is by crossing a group of other ice shelves, all of which are perfectly circular. He is very scared, and can not swim. Barney’s mother, getting a little tired of her son’s shenanigans, decides to wait and let him figure this out for himself. Can you help Barney get home? He is in a hurry.

Input

  • The first line of input contains four integers, $-10^6 \leq x_ b, y_ b, x_ m, y_ m \leq 10^6$, where $(x_ b, y_ b)$ is Barney’s location and $(x_ m, y_ m)$ is the location where Barney’s mom is waiting.

  • The next line contains a single integer $1 \leq n \leq 25$, the number of ice shelves.

  • After this $n$ lines follow. Each line holds three integers: $-10^6 \leq x_ i, y_ i \leq 10^6$ and $1 \leq r_ i \leq 10^6$, the coordinates of the center of the shelf and its radius. A shelf consists of all points at distance $r_ i$ or less to $(x_ i, y_ i)$.

Both bears are on a shelf at the start of Barney’s journey home. Shelves can both touch and overlap.

Output

The minimal distance Barney has to travel to be reunited with his mother. The result should have a relative error of at most $10^{-6}$.

If there is no way for Barney to make it home, output “impossible”. (Do not worry about Barney’s well-being in this scenario. His mother will swim out to save him.)

\includegraphics[width=.4\textwidth ]{3.pdf}
Figure 1: Illustration of the third example input.
Sample Input 1 Sample Output 1
0 0 6 0
2
1 1 2
5 1 2
6.32455532034
Sample Input 2 Sample Output 2
0 0 7 0
2
1 1 2
6 1 2
impossible
Sample Input 3 Sample Output 3
0 0 1 3
3
0 -1 2
4 -1 3
2 3 2
4.269334912857045697