Mock CCC '20 Contest 1 S5 - Maze 🍆

View as PDF

Submit solution

Points: 30
Time limit: 20.0s
Memory limit: 256M

Problem type

One day, Jonathan is stuck inside of a large maze. Completely lost, he asks Raymond to help him get out of the maze. Unwilling to see Jonathan escape from the maze without thought, Raymond decides to only give him hints.

"Your starting point is at (x_s,y_s), and the exit is at (x_g,y_g)," says Raymond.

"That seems easy...then why can't I get out of this maze?" replies Jonathan.

"Your path is blocked by several walls. There are N walls in the maze. The walls can be represented as line segments. The i^{th} wall has two different endpoints (x_{i1},y_{i1}) and (x_{i2},y_{i2}). You cannot intersect these walls, but you can walk along them."

"That sounds simple enough."

What is the shortest distance that Jonathan has to travel to exit the maze?

Constraints

0 \le N

The absolute value of any coordinate will not exceed 10^9.

The start point and exit are located at distinct points and will not be on any line.

A line's endpoints will not be on another line anywhere except the latter line's endpoints. If two lines share an endpoint, the angle will be between 1^{\circ} and 359^{\circ}.

Subtask Points N Additional Constraints
1 3 N \le 1 No additional constraints.
2 3 N \le 200 All points are pairwise distinct. This includes the starting point, the exit, and all endpoints.
3 4 N \le 200 No additional constraints.
4 5 N \le 2\,000 No additional constraints.

Input Specification

The first line of input will contain five space-separated integers, N, x_s, y_s, x_g, and y_g.

N lines of input will follow. The i^{th} line will contain four space-separated integers, x_{i1}, y_{i1}, x_{i2}, and y_{i2}.

Output Specification

On a single line, output the shortest distance that Jonathan has to travel to exit the maze. Your answer will be judged as correct if it has an absolute or relative error no greater than 10^{-6}.

If it is not possible for Jonathan to travel to the exit, print No exit.

Sample Input 1

1 0 0 1 1
1 0 0 1

Sample Output 1

2.00000000

Diagram for Sample 1

sample 1 diag

The blue points represent the starting and ending points, the green line represents the wall, and the dotted red line shows an optimal path.

Sample Input 2

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

Sample Output 2

7.07106781

Diagram for Sample 2

samp 2 diag

The blue points represent the starting and ending points, the green lines represent the walls, and the dotted red line shows the optimal path.


Comments

There are no comments at the moment.