Meet The Plastics I
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.
Luckily, Cady is allowed to wear the same color any number of times.
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 colours of 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 Redis 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
Pink
Pink
Pink
Cady can successfully follow Regina's fashion rules.
Input 3
1
Rainbow
3
No 1 Rainbow
No 1 Rainbow
No 1 Rainbow
Output 3
No
Cady can't avoid wearing rainbow.
Input 4
3
Red
Green
Blue
2
Yes Pink
Yes Red
Output 4
No
Cady can't wear pink when Regina wants her to.
Comments