Intelligent Robot
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given a maze of size , whose lower-left corner is while upper-right corner is . And there are segment walls in the maze. One cannot cross the walls but can touch them or walk along them. Now a MI robot is assigned to go from (X_1, Y_1) to (X_2, Y_2), as an intelligent robot, MI robot will automatically determine the shortest valid path and go along it. Print the length of the shortest valid path between (X_1, Y_1) and (X_2, Y_2).

输入描述:

The first line contains three integers , denoting the size of the maze and the number of walls respectively.

Following k lines each contains four integers , denoting a segment wall (x_1,y_1) - (x_2,y_2).

The next line contains four integers , denoting the two given points.

It's guaranteed that no two segment walls share common points, and that no segment wall covers (X_1, Y_1) or (X_2, Y_2), and that either or .

输出描述:

Only one line containing a real number with four decimal places after the decimal point, denoting the answer.

It's guaranteed that the fifth decimal place after the decimal point is neither 4 nor 5.
示例1

输入

复制
6 3 2
1 1 3 1
2 2 5 2
3 0 3 3

输出

复制
3.8284

说明

One possible way is (3, 0) \rightarrow (3, 1) \rightarrow (2, 2) \rightarrow (3, 3), and the exact answer is 2\sqrt{2} + 1.