Meet The Plastics II
Cady has just met Regina George, Gretchen Wieners, and Karen Smith — a clique of popular girls known as The Plastics. She loves sitting with them at lunch, but have some strict fashion rules.
Each day, Regina creates a rule that Cady must follow:
- She either forbids Cady from wearing a list of specific colors, or
- She requires Cady to wear a specific color.
To make things even more stressful, Cady is not allowed to wear the same color two days in a row.
Cady has a limited wardrobe. Can she plan her outfits to satisfy Regina's rules?
Input
The first line contains an integer
— the number of colors in Cady's wardrobe.
The next lines each contain a color name — these are the clothes Cady owns. Each color name is a string of length
.
The next line contains an integer
— the number of days Cady must follow the fashion rules.
The next lines each describe a rule for the corresponding day. Each rule is either:
No k C1 C2 C3 ... Ck
— Cady cannot wear any of theforbidden colors (
), each color name is a string of length (
).
Yes C
— Cady must wear the coloron that day.
Output
If Cady can satisfy Regina's fashion rules, output the color she should wear on each day, in order. Otherwise, output "No".
Clarifications
- If there are multiple answers, output any of them.
- The colors in Cady's wardrobe are unique.
- The colors in each "No" clause are unique for that clause (e.g.
No 2 Red Red
is not possible).
Example
Input 1
5
Red
Blue
Green
Yellow
Pink
5
No 3 Red Green Blue
No 1 Yellow
Yes Pink
No 3 Red Green Black
Yes Yellow
Output 1
Yellow
Red
Pink
Blue
Yellow
Cady can successfully follow Regina's fashion rules.
Input 2
2
Pink
Red
3
No 3 Red Green Blue
No 3 Red Green Blue
No 3 Red Green Blue
Output 2
No
Cady can wear pink on the first day, but then she doesn't have any clothes to wear on the last two days.
Input 3
1
Red
3
No 1 Rainbow
No 1 Rainbow
No 1 Rainbow
Output 3
No
Cady doesn't have enough clothes to wear, as to not wear the same thing twice in a row.
Input 4
4
Red
Pink
Green
Blue
2
Yes Pink
Yes Pink
Output 4
No
Regina wants Cady to wear pink twice, but she can't wear the same thing twice in a row.
Comments