X-Mart

Time limit1sMemory limit128 MB

Summary
Given customers who each vote for up to two products to keep and against up to two to drop, decide whether some keep/drop assignment pleases all of them.
Level

Medium7 of 10

Topics
Graph, DFS, Implementation, Math
Solved
No attempts yet

Problem

The well-known supermarket chain X-Mart decided to cut costs by reducing the number of different products it keeps on its shelves. The marketing department worried this would hurt sales, so it decided to turn the reduction into an opportunity to improve customer relations.

X-Mart therefore ran an Internet poll in which customers could choose which products they wanted the supermarket to keep on its shelves and which products they wanted it to withdraw. The list of currently available products was published online.

To keep the poll simple, each customer may choose at most two products to vote for (the supermarket should keep selling them) and at most two products to vote against (the supermarket should stop selling them).

Once every vote is collected, the marketing department wants to know whether it can choose a new product list that pleases all voting customers. A customer is pleased when at least one of the products they voted for is actually kept, and at least one of the products they voted against is actually withdrawn. You may assume that no customer votes both for and against the same product.

Input

Your program must process several test cases. The first line of a test case contains two integers CC and PP, the number of customers and the number of products (1≤C≤10001 \le C \le 1000 and 1≤P≤100001 \le P \le 10000). Each of the next CC lines describes one customer's preferences as four integers XX, YY, SS, TT (0≤X,Y,S,T≤P0 \le X, Y, S, T \le P). XX and YY are products the customer wants kept, and SS and TT are products the customer wants withdrawn. A value of 00 for any of XX, YY, SS, TT means that vote is unused. A line with C=P=0C = P = 0 ends the input.

Output

For each test case, print a single line containing yes if it is possible to please all voting customers, or no if it is not.

Examples3

  1. Example 1

    Input
    3 4 
    1 2 3 4 
    3 4 1 2 
    2 3 1 4 
    4 4 
    1 2 3 4 
    3 4 1 2 
    1 3 2 4 
    1 4 2 3 
    4 4 
    1 2 3 4 
    3 4 1 0 
    1 3 2 4 
    2 4 0 3
    0 0
    
    Expected output
    yes
    yes
    no
    
  2. Example 2

    Input
    1 2
    1 0 2 0
    0 0
    
    Expected output
    yes
    
  3. Example 3

    Input
    2 2
    1 0 2 0
    2 0 1 0
    0 0
    
    Expected output
    no