atcoder#ABC286H. [ABC286Ex] Don’t Swim

[ABC286Ex] Don’t Swim

Score : 600600 points

Problem Statement

On a two-dimensional plane, there is a convex polygon CC with NN vertices, and points S=(sx,sy)S=(s_x, s_y) and T=(tx,ty)T=(t_x,t_y). The vertices of CC are (x1,y1),(x2,y2),(x_1,y_1),(x_2,y_2),\ldots, and (xN,yN)(x_N,y_N) in counterclockwise order. It is guaranteed that SS and TT are outside the polygon.

Find the shortest distance that needs to be traveled to get from point SS to point TT without entering the interior of CC except for its circumference.

Constraints

  • 3N1053\leq N \leq 10^5
  • xi,yi,sx,sy,tx,ty109|x_i|,|y_i|,|s_x|,|s_y|,|t_x|,|t_y|\leq 10^9
  • (x1,y1),(x2,y2),(x_1,y_1),(x_2,y_2),\ldots, and (xN,yN)(x_N,y_N) form a convex polygon in counterclockwise order.
  • No three points of CC are colinear.
  • SS and TT are outside CC and not on the circumference of CC.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

x1x_1 y1y_1

x2x_2 y2y_2

\vdots

xNx_N yNy_N

sxs_x sys_y

txt_x tyt_y

Output

Print the answer.

Your output is considered correct if the absolute or relative error from the true value is at most 10610^{-6}.

4
1 1
3 1
3 3
1 3
0 2
5 2
5.65028153987288474496

One way to achieve the shortest distance is shown in the following figure.

image

If you travel as (0,2)(1,3)(3,3)(5,2)(0,2) \to (1,3) \to(3,3)\to(5,2), the length of the path from point SS to point TT is 5.650281...5.650281.... We can prove that it is the minimum. Note that you may enter the circumference of CC.

Note that your output is considered correct if the absolute or relative error is at most 10610^{-6}. For example, output like 5.650287 is also considered correct.

3
0 0
2 0
1 10
3 7
10 3
8.06225774829854965279