This page is still under construction.

Parts of this page are still being built. What you see may change.

ACM Underground

Time limit1sMemory limit128 MB

Summary
Given metro lines, policemen on them, and two points, decide whether the destination is reachable without ever being checked, where checks happen at line changes and at non-intersection spots on lines.
Level

Hard8 of 10

Topics
Geometry, Graph, BFS, Implementation
Solved
No attempts yet

Statement

ACM is a town with a special underground metro system built from railway segments; each segment is called a line. Every line runs trains in both directions. Two lines may intersect, and at an intersection point a passenger can switch from a train on one line to a train on the other.

The source and destination of your trip both lie somewhere on the metro lines. You board on the line that the source lies on, you may change lines only at intersection points between two lines, and you keep going until you reach the destination. Your goal is to make the whole trip free of charge, that is, without ever buying a ticket.

The obstacle is a group of policemen who check tickets, and you must never let one check yours. You can be checked in exactly two situations:

  • At an intersection, but only if you actually change lines there. A policeman standing on an intersection checks you only when you switch lines at that point; if you merely pass through it while staying on the same line, he ignores you.
  • While riding along a line, if you pass the exact spot of a policeman who stands on that line but not on an intersection. Such a policeman checks everyone who rides past his spot.

Policemen who are not on any metro line are irrelevant and must be ignored. You know every policeman's position in advance.

For example, in the figure above there are five metro lines and three policemen (the black circles). You can travel from ss to dd along lines l1→l4l_1 \rightarrow l_4 without meeting any policeman, but there is no way to travel from ss to d′d' without being checked.

Write a program that reads the metro lines, the policemen, and the source and destination, and decides whether it is possible to travel from the source to the destination without being checked by any policeman.

Input

The first line contains an integer TT, the number of test cases. Each test case has the following form:

  • One line with two integers nn and mm (1≤m≤1001 \le m \le 100, 1≤n≤30001 \le n \le 3000): the number of metro lines and the number of policemen.
  • One line with four integers xs ys xd ydx_s\ y_s\ x_d\ y_d: the coordinates of the source (xs,ys)(x_s, y_s) and the destination (xd,yd)(x_d, y_d). Both points are guaranteed to lie on metro lines.
  • nn lines, each with four integers x1 y1 x2 y2x_1\ y_1\ x_2\ y_2, giving the two endpoints (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) of one metro line.
  • mm lines, each with two integers x yx\ y, giving the position of one policeman.

All coordinates are arbitrary integers.

Output

Print TT lines, one per test case in the same order as the input. For each test case print a single word: YES if there is a safe way to travel from the source to the destination without being checked, or NO otherwise.

Examples6

  1. Example 1

    Input
    2
    4 2
    3 2 5 8
    3 2 3 6
    8 1 5 8
    7 7 2 2
    9 2 1 6
    3 4
    6 6
    3 2
    2 3 6 3
    1 3 7 3
    3 2 3 6
    1 5 7 2
    3 4
    4 3
    
    Expected output
    YES
    NO
    
  2. Example 2

    Input
    1
    1 0
    0 0 10 0
    0 0 10 0
    
    Expected output
    YES
    
  3. Example 3

    Input
    1
    1 1
    0 0 10 0
    0 0 10 0
    5 0
    
    Expected output
    NO
    
  4. Example 4

    Input
    1
    3 1
    0 0 10 0
    0 0 10 0
    2 0 5 5
    5 5 8 0
    5 0
    
    Expected output
    YES
    
  5. Example 5

    Input
    1
    2 1
    0 0 10 0
    0 0 10 0
    5 -5 5 5
    5 0
    
    Expected output
    YES
    
  6. Example 6

    Input
    1
    2 0
    0 0 5 5
    0 0 10 0
    5 -5 5 5
    
    Expected output
    YES