eolymp
bolt
Try our new interface for solving problems
Məsələlər

Repairing

Repairing

In the International City of Pipe Construction, it is planned to repair the water pipe at a certain point in the water pipe network. The network consists of water pipe segments, stop valves and source point. A water pipe is represented by a segment on a \textbf{2D}-plane and intersected pair of water pipe segments are connected at the intersection point. A stop valve, which prevents from water flowing into the repairing point while repairing, is represented by a point on some water pipe segment. In the network, just one source point exists and water is supplied to the network from this point. Of course, while repairing, we have to stop water supply in some areas, but, in order to reduce the risk of riots, the length of water pipes stopping water supply must be minimized. What you have to do is to write a program to minimize the length of water pipes needed to stop water supply when the coordinates of end points of water pipe segments, stop valves, source point and repairing point are given. \InputFile A data set has the following format: \textbf{N M} \textbf{x_s1 y_s1 x_d1 y_d1} \textbf{...} \textbf{x_sN y_sN x_dN y_dN} \textbf{x_v1 y_v1} \textbf{...} \textbf{x_vM y_vM} \textbf{x_b y_b} \textbf{x_c y_c} The first line of the input contains two integers, \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{300}) and \textbf{M} (\textbf{0} ≤ \textbf{M} ≤ \textbf{1000}) that indicate the number of water pipe segments and stop valves. The following \textbf{N} lines describe the end points of water pipe segments. The \textbf{i}-th line contains four integers, \textbf{x_si}, \textbf{y_si}, \textbf{x_di} and \textbf{y_di} that indicate the pair of coordinates of end points of \textbf{i}-th water pipe segment. The following \textbf{M} lines describe the points of stop valves. The \textbf{i}-th line contains two integers, \textbf{x_vi} and \textbf{y_vi} that indicate the coordinate of end points of \textbf{i}-th stop valve. The following line contains two integers, \textbf{x_b} and \textbf{y_b} that indicate the coordinate of the source point. The last line contains two integers, \textbf{x_c} and \textbf{y_c} that indicate the coordinate of the repairing point. You may assume that any absolute values of coordinate integers are less than \textbf{1000} (inclusive.) You may also assume each of the stop valves, the source point and the repairing point is always on one of water pipe segments and that that each pair among the stop valves, the source point and the repairing point are different. And, there is not more than one intersection between each pair of water pipe segments. Finally, the water pipe network is connected, that is, all the water pipes are received water supply initially. \OutputFile Print the minimal length of water pipes needed to stop water supply in a line. The absolute or relative error should be less than or \textbf{10^\{−6\}}. When you cannot stop water supply to the repairing point even though you close all stop valves, print "\textbf{-1}" in a line.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
1 2
0 0 10 0
1 0
9 0
0 0
5 0
Çıxış verilənləri #1
9.0
Mənbə JAG Summer 2012, Japan