Lazy employees P76991


Statement
 

pdf   zip

Xavier works at a company with nn employees (between 0 and n1n-1) and qq tasks to do (between 0 and q1q-1). Every task has a list of all the employees that can do it. Note that it is allowed that more than one employee does the same task, and that the same employee does more than one task. There are \ell employees that are really lazy, and they will not work under any circumstances. Moreover, there are ee eccentric employees. Each such employee xx has a list of employees such that xx will only accept to work if at least one of the employees of his list also works. Under all those constraints, is it possible to do all the tasks of the company?

Input

Input consists of several cases. Every case begins with nn and qq. Follow qq lines: the ii-th line starts with a number mim_i between 1 and nn, followed by a list of mim_i different employees that can do task ii. Follow \ell and the \ell lazy employees. Finally, we have information about the eccentricities: First we have ee, followed by ee lines, each one with an eccentric employee xx, a number rxr_x between 1 and n1n-1, followed by a list of the rxr_x employees in xx’s list (all different and x\ne x). Assume that nn and qq are between 1 and 10410^4, mi5q\sum m_i \le 5q, rx5n\sum r_x \le 5n, and 0+en0 \le \ell + e \le n. The lazy and the eccentric employees are all different.

Output

For each case, print “YES” if all the tasks can be done, and “NO” otherwise.

Public test cases
  • Input

    1 1
    1  0
    0
    0
    
    5 2
    4  3 2 1 0
    5  0 1 2 3 4
    2  1 0
    2
    2 2  0 1
    3 2  2 1
    
    3 2
    1  1
    2  1 0
    1  2
    2
    1 1  0
    0 1  1
    

    Output

    YES
    NO
    YES
    
  • Information
    Author
    Edgar Moreno
    Language
    English
    Official solutions
    C++
    User solutions
    C++