#P6761. [BalticOI 2010] BEARs (Day1)
[BalticOI 2010] BEARs (Day1)
Description
You are given line segments of length , defined as “marked segments”.
Now there is a robber at point , and he wants to go to . The police may choose any point and block any one line segment around it. For example, if they choose point , then one of the following segments will be blocked: , , , . However, among the segments that are blocked, there must not be any segment that is directly connected to a marked segment. For example, and are directly connected, but and are not.
The robber may reach points on a blocked segment, but he cannot leave by crossing the blocked segment.
Find the maximum value of the robber’s minimum distance to .
Input Format
The first line contains two integers , representing that the robber initially is at .
The second line contains one integer , representing the number of marked segments.
The next lines each contain four integers , representing a marked segment .
Output Format
Output one integer, representing the maximum value of the robber’s minimum distance to .
3 3
3
1 0 3 0
0 0 0 3
3 0 3 1
1
Hint
Sample Explanation
For sample , as shown in the figure below:

The chosen point is , and the blocked segment is .
Constraints
For of the testdata, , . It is guaranteed that for each marked segment, or .
Note
Translated from BalticOI 2010 Day1 A BEARs.
Translated by ChatGPT 5
京公网安备 11011102002149号