Lazy employees

Xavier works at a company with n employees (between 0 and n − 1) and q
tasks to do (between 0 and q − 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 ℓ employees that are really lazy, and they will not
work under any circumstances. Moreover, there are e eccentric employees.
Each such employee x has a list of employees such that x 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 n and q. Follow
q lines: the i-th line starts with a number m_(i) between 1 and n,
followed by a list of m_(i) different employees that can do task i.
Follow ℓ and the ℓ lazy employees. Finally, we have information about
the eccentricities: First we have e, followed by e lines, each one with
an eccentric employee x, a number r_(x) between 1 and n − 1, followed by
a list of the r_(x) employees in x’s list (all different and  ≠ x).
Assume that n and q are between 1 and 10⁴, ∑m_(i) ≤ 5q, ∑r_(x) ≤ 5n, and
0 ≤ ℓ + e ≤ 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.

Problem information

Author: Edgar Moreno

Generation: 2026-01-25T11:55:35.589Z

© Jutge.org, 2006–2026.
https://jutge.org
