방향이 있는 여러 선분 위를 지나는 레이저 커터가 모든 선분을 잘라내고 시작점으로 돌아오는 최단 경로의 길이를 구한다.
어려움8그래프동적 계획법기하시뮬레이션아직 제출이 없습니다시간 제한5초메모리 제한512 MBCiel 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 (x,y). Ciel can conduct the following two operations:
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.
The first line of the input contains an integer n (1≤n≤300), the number of segments. The next line contains two integers x and y (−1,000≤x,y≤1,000), which is the initial position (x,y) of the laser. The i-th of the following n lines contains four integers sx_i, sy_i, tx_i and ty_i (−1,000≤sx_i,sy_i,tx_i,ty_i≤1,000), which indicate that they are the end points of the i-th segment, and that the laser cutter can cut the board in the direction from (sx_i,sy_i) to (tx_i,ty_i). The input satisfies the following conditions: For all i (1≤i≤n), (sx_i,sy_i)=(tx_i,ty_i). The initial point (x,y) lies on at least one of the given segments. For all distinct i,j (1≤i,j≤n), the i-th segment and the j-th segment share at most one point.
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 10−6.