ZOJ Problem Set - 3348
DD enters the top-level pingpong match! As the game going on, he wonders if there is possibility for him to get the champion(excluding joint champions). Now provide you the results of previous matches, and the details of rest matches. You have to judge it.
There are several test cases. You should process to the end of input.
For each test case. the first line contain two integers n (1 <= n <= 50) and m(0 <= m <= 1000), n indicates the number of players. m indicates the matches have ended.
Then for the following m lines, each line has the format: "Player1 Player2 Result". Player1 and Player2 are the names of the two players, and Result could only be "win" or "lose".
In the next line there is another integer p (0 <= p <= 5000), indicates the matches that will start later.
Then for the following p lines, each line has the format: "Player1 Player2", which means Player1 and Player2 will start a match.
We ensure there is a player named "DD". The length of each player name is no longer than 10.
You should only output "Yes" or "No" for each case, which means if DD has the possibility to be the champion.
3 2 DD winsty win DD owen lose 2 winsty owen DD owen 3 3 DD winsty win DD owen lose winsty owen lose 2 owen winsty owen DD
Author: WANG, Naiyan
Contest: ZOJ Monthly, June 2010