uses
	testlib, sysutils;

const
	maxn = 300;

var
	ja, pa: string;
	i, j, n, m, ss: longint;
	l: array [1..maxn] of longint;
	v: array [1..maxn] of longint;
	x: array [1..maxn, 1..maxn] of longint;

begin
	ja := ans.readword(blanks, blanks);
	pa := ouf.readword(blanks, blanks);

	if (pa = 'NO') then begin
		if ja = 'NO' then
			quit(_ok, 'NO')
		else
			quit(_wa, 'NO unexpected')
	end;

	n := inf.readlongint;
	m := inf.readlongint;
	for i := 1 to m do begin
		l[i] := inf.readlongint;
		for j := 1 to l[i] do begin
			x[i][j] := inf.readlongint;
		end;
	end;

	for i := 1 to n do begin
		v[i] := ouf.readlongint;
		if (v[i] <> 0) and (v[i] <> 1) then
			quit(_wa, format('0 or 1 expected, %d found', [v[i]]));
	   	v[i] := 2 * v[i] - 1;
	end;

	for i := 1 to m do begin
		ss := 0;
		for j := 1 to l[i] do begin
			if v[abs(x[i][j])] * x[i][j] > 0 then
				inc(ss);
		end;
		if (ss <> 1) then
			quit(_wa, format('clause %d has %d satisfied terms', [i, ss]));
	end;

	if ja = 'NO' then
		quit(_fail, 'NO expected');

	quit(_ok, 'YES');
end.
	