#icpc2015summerday4h. [icpc2015summer_day4_h]Laser Cutter
[icpc2015summer_day4_h]Laser Cutter
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
Ciel is going to do woodworking. Ciel wants to make a cut in a wooden board using a laser cutter.
To make it simple, we assume that the board is a two-dimensional plane. There are several segments on the board along which Ciel wants to cut the board. Each segment has a direction and Ciel must cut those segments along their directions. Those segments are connected when you ignore the directions, that is, any two points on the segments are directly or indirectly connected by the segments.
While the laser cutter is powered on, it emits a laser which hits the board at a point and cuts the board along its trace. The laser initially points to . Ciel can conduct the following two operations:
- Move the laser cutter with its power on and cut (a part of) a segment along its direction, or
- Move the laser cutter to any position with its power off. Ciel should not necessarily cut the whole segment at a time; she can start or stop cutting a segment at any point on the segments.
Ciel likes to be efficient, so she wants to know the shortest route such that the laser cutter cuts the whole parts of all the segments and then move back to the initial point. Your task is to write a program that calculates the minimum total moving distance of the laser cutter.
Input
The first line of the input contains an integer (), the number of segments. The next line contains two integers and (), which is the initial position of the laser. The -th of the following lines contains four integers , , and ($-1{,}000 \\leq sx\_i, sy\_i, tx\_i, ty\_i \\leq 1{,}000$), which indicate that they are the end points of the -th segment, and that the laser cutter can cut the board in the direction from to . The input satisfies the following conditions: For all (), . The initial point lies on at least one of the given segments. For all distinct (), the -th segment and the -th segment share at most one point.
Output
Output a line containing the minimum total moving distance the laser cutter needs to travel to cut all the segments and move back to the initial point. The absolute error or the relative error should be less than .
Sample Input 1
3
0 1
0 0 0 1
0 1 0 2
0 2 0 3```
### Output for the Sample Input 1
```plain
6.0000000000000000```
* * *
### Sample Input 2
```plain
2
0 1
0 0 0 2
-1 1 1 1```
### Output for the Sample Input 2
```plain
6.8284271247461900```
* * *
### Sample Input 3
```plain
5
0 0
0 0 1 0
1 1 -1 1
-1 1 -1 -1
-1 -1 1 -1
1 -1 1 1```
### Output for the Sample Input 3
```plain
10.0000000000000000```
* * *