Codeforces Round 138 (Div. 1) |
---|
Finished |
A plane contains a not necessarily convex polygon without self-intersections, consisting of n vertexes, numbered from 1 to n. There is a spider sitting on the border of the polygon, the spider can move like that:
Initially the spider is located at the polygon vertex with number s. Find the length of the shortest path to the vertex number t, consisting of transfers and descends. The distance is determined by the usual Euclidean metric .
The first line contains integer n (3 ≤ n ≤ 105) — the number of vertexes of the given polygon. Next n lines contain two space-separated integers each — the coordinates of the polygon vertexes. The vertexes are listed in the counter-clockwise order. The coordinates of the polygon vertexes do not exceed 104 in their absolute value.
The last line contains two space-separated integers s and t (1 ≤ s, t ≤ n) — the start and the end vertexes of the sought shortest way.
Consider the polygon vertexes numbered in the order they are given in the input, that is, the coordinates of the first vertex are located on the second line of the input and the coordinates of the n-th vertex are on the (n + 1)-th line. It is guaranteed that the given polygon is simple, that is, it contains no self-intersections or self-tangencies.
In the output print a single real number — the length of the shortest way from vertex s to vertex t. The answer is considered correct, if its absolute or relative error does not exceed 10 - 6.
4
0 0
1 0
1 1
0 1
1 4
1.000000000000000000e+000
4
0 0
1 1
0 2
-1 1
3 3
0.000000000000000000e+000
5
0 0
5 0
1 4
0 2
2 1
3 1
5.650281539872884700e+000
In the first sample the spider transfers along the side that connects vertexes 1 and 4.
In the second sample the spider doesn't have to transfer anywhere, so the distance equals zero.
In the third sample the best strategy for the spider is to transfer from vertex 3 to point (2,3), descend to point (2,1), and then transfer to vertex 1.
Name |
---|