#A1002. 【模板】2-SAT
【模板】2-SAT
题目描述
题目源自 hdu 4115。Mars 注:其实英文题面不难。
Conflicts are everywhere in the world, from the young to the elderly, from families to countries. Conflicts cause quarrels, fights or even wars. How wonderful the world will be if all conflicts can be eliminated.
Edward contributes his lifetime to invent a 'Conflict Resolution Terminal' and he has finally succeeded. This magic item has the ability to eliminate all the conflicts. It works like this:
If any two people have conflict, they should simply put their hands into the 'Conflict Resolution Terminal' (which is simply a plastic tube). Then they play 'Rock, Paper and Scissors' in it. After they have decided what they will play, the tube should be opened and no one will have the chance to change. Finally, the winner have the right to rule and the loser should obey it. Conflict Eliminated!
But the game is not that fair, because people may be following some patterns when they play, and if the pattern is founded by others, the others will win definitely.//这四段写石头剪刀布能消除矛盾,但 Bob 出的有规律
Alice and Bob always have conflicts with each other so they use the 'Conflict Resolution Terminal' a lot. Sadly for Bob, Alice found his pattern and can predict how Bob plays precisely. She is very kind that doesn't want to take advantage of that. So she tells Bob about it and they come up with a new way of eliminate the conflict:
They will play the 'Rock, Paper and Scissors' for round. Bob will set up some restricts on Alice.
But the restrict can only be in the form of "you must play the same (or different) on the and rounds". If Alice loses in any round or break any of the rules she loses, otherwise she wins.
Will Alice have a chance to win?
输入格式
The first line contains an integer , indicating the number of test cases.
Each test case contains several lines.
The first line contains two integers , representing how many round they will play and how many restricts are there for Alice.
The next line contains integers , where represents what item Bob will play in the round. represents Rock, represents Paper, represents Scissors.//即 Bob 所出的
The following lines each contains three integers represent a restrict for Alice. If equals , Alice must play the same on and round. If equals , she must play different items on and round.//限制要求
输出格式
For each test case in the input, print one line: 'Case #X: Y', where is the test case number (starting with ) and is yes
or no
represents whether Alice has a chance to win.
样例
Input:
2
3 3
1 1 1
1 2 1
1 3 1
2 3 1
5 5
1 2 3 2 1
1 2 1
1 3 1
1 4 1
1 5 1
2 3 0
Output:
Case #1: no
Case #2: yes
数据范围与提示
Hint:
'Rock, Paper and Scissors' is a game which played by two person. They should play Rock, Paper or Scissors by their hands at the same time. Rock defeats scissors, scissors defeats paper and paper defeats rock. If two people play the same item, the game is tied.