[Login|Register]
Problems

Status

Rank

Problem 1140
Course arrangement
Time Limit: 1000ms
Memory Limit: 65536kb
Description
In the course selecting procedure in USTC, poor Eric always couldn't get his wish.
Course Selection is primarily limited by two aspects.
(I)the upper bound of student number of a subject.
(II)conflict in schedule -- you can't take two classes simultaneously.
He collected the information of all subjects and every undergraduate's interests. Please help him write a program to judge whether there is an all-satisfying arrangement.
Input
The input contains serveral cases, each test case with following format.

First line is an integer C (C<1400), the number of the courses.
The following C lines each contains two stirngs and an integer. First string is the course name, and the second one is the day in which the class is on, which must be one of {"Monday", "Tuesday", "Wednesday", "Thursday" and "Friday"}. The integer represents the max student number limit of that course.
Next line is an integer N (N<700), the number of the students.
N lines follow. Each line begins with two integers K and X, which means: this student is willing to choose X courses from K ones (X<=K<700). The rest of each line is composed of K strings, the names of the K courses.

There is a blank line between two cases.

The input will be terminated by a case both C and K are 0.

The string of course name consists of only letters, and its length is not longer than 16.
Output
Output "Yes!" in a line if there is an all-satisfying arrangement. Otherwise, output "No.".
Sample Input
2
psychology Tuesday 1
modernBiology Thursday 2
3
2 1 psychology modernBiology
1 1 psychology
1 1 modernBiology

3
mathematica Monday 2
esthetics Tuesday 1
Java Tuesday 1
3
1 1 mathematica
1 1 mathematica
3 2 mathematica esthetics Java

0
0
Sample Output
Yes!
No.
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 1.5ms with 1 query(s).