QOJ.ac

QOJ

Limite de temps : 3 s Limite de mémoire : 256 MB Points totaux : 100

#557. Streets

Statistiques

Background

The transportation system in the capital of JSOI is very complex. JYY is currently thinking about how to quickly reach the meeting place with the princess.

Description

There are $N$ streets in the capital of JSOI, and each street is a line segment that is either vertical or horizontal. JYY starts from $(sx, sy)$ and hopes to reach $(tx, ty)$.

JYY can only move horizontally or vertically along the streets. If a point lies on two line segments simultaneously, JYY can switch from one street to another at this point.

JYY hopes you can help him calculate the shortest path distance.

Input

The first line contains a positive integer $N$, representing the number of streets.

The following $N$ lines each contain 4 integers $xi_1, yi_1, xi_2, yi_2$, representing that the $i$-th street is from $(xi_1, yi_1)$ to $(xi_2, yi_2)$.

The $(N+2)$-th line contains 4 integers $sx, sy, tx, ty$, representing the starting point and the destination. It is guaranteed that the starting point and the destination lie on some street.

Output

Output an integer representing the length of the shortest path. It is guaranteed that the input has a solution.

Constraints

  • For 30% of the data, $N \le 200$.
  • For 100% of the data, $N \le 10000$.
  • The input guarantees that every street is either horizontal or vertical, and no two streets overlap (any two streets have at most one intersection point). All coordinates have absolute values less than or equal to $10^9$.

Examples

Input 1

8
0 0 0 2
0 2 2 2
2 2 2 0
2 0 0 0
-1 1 1 1
1 1 1 3
1 3 -1 3
-1 1 -1 3
2 0 -1 3

Output 1

6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.