Victory Through Synergy

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

Johnny has been roped into a fantasy soccer league and needs your help to set up the best team.

He has a list of 1010 players that are on his fantasy team (no goalkeepers in this league). He also knows what country they're from, what league they play in, and what team they play for.

He doesn't know much about soccer, but he does know these things:

  1. If two players are from the same country, a link between the two players will have a synergy score of 11.
  2. If two players are in the same league, a link between the two players will have a synergy score of 11.
  3. If two players are on the same team, a link between the two players will have a synergy score of 22.
  4. If two players are from the same country and in the same league, a link between the two players will have a synergy score of 22.
  5. If two players are from the same country and on the same team, a link between the two players will have a synergy score of 33.

A team can only be in one league and no two teams will have the same name unless they are the same team.

He has to place the players on his team into a formation of 1010 nodes which can be represented as an undirected graph. The illustration shows the first sample. Therefore, Johnny has to place a player in each node of the graph. Given a particular formation and the members of Johnny's team, output whether it is possible for Johnny to organize his team to get a perfect team.

A team is a perfect team if and only if every player is placed on a node with a synergy score that is greater or equal to the node's degree. A node's degree is the number of links to which it is linked in the formation. A player placed on a node in the formation derives synergy from all players placed on nodes to which the player is linked in the formation.  Thus, a node's synergy score is the sum of the synergy scores of all links to which the node is connected.

입력

The input will contain 11 test case. The first line of the input will have one integer cc (0c450 \leq c \leq 45). cc represents the number of edges in the formation. The next cc lines represent the connections between nodes represented as two integers aa (0a<100 \leq a < 10) and bb (0b<100 \leq b < 10), where aa is not equal to bb. Then, the next 1010 lines will be the players on Johnny's team. Each line will contain four strings in the following order: player name, nation, league, team. These are guaranteed to be non-empty with no spaces, no longer than 1515 characters, and delimited by a single space between each piece of information.

출력

If a perfect team can be organized by Johnny, print yes. Otherwise, print no.