#P8091. [USACO22JAN] Non-Transitive Dice B
[USACO22JAN] Non-Transitive Dice B
Problem Description
To pass the time in the barn, the cows like to play simple dice games. One such game uses two dice and . Both dice are rolled, and the die showing the larger number wins. If they show the same number, they are rolled again (as long as the rolls keep tying, the dice may be rolled multiple times). We say die beats die if die is more likely than die to win this game.
Consider the following 4-sided dice:
Die A has numbers , , , and on its faces.
Die B has numbers , , , and on its faces.
Die C has numbers , , , and on its faces.
These dice have a rather amazing property: A beats B, B beats C, and C also beats A. In particular, none of the three dice is the “best” one that can beat the other two. In this situation, when no two dice tie and no die is the best, we call the set of three dice “non-transitive”. In a non-transitive set of three dice, each die beats one of the other dice and loses to the other.
Given the face values of two 4-sided dice A and B, please help the cows determine whether there is a way to assign numbers to the faces of a third die C so that the set of dice is non-transitive. All face values must be integers from to .
Input Format
Each test contains multiple independent subtasks. All subtasks must be answered correctly to pass the entire test. The first line of input contains (), the number of subtasks you need to solve.
The next lines each describe one subtask and contain integers: the face values of die A, followed by the face values of die B. All values are between and , and are not necessarily sorted. The same number may appear multiple times, even on the same die.
Output Format
Output lines. If it is possible to assign numbers to die C so that the -th subtask becomes a non-transitive set of dice, output yes on the -th line; otherwise output no.
3
4 5 6 7 2 4 5 10
2 2 2 2 1 1 1 1
1 1 1 1 2 2 2 2
yes
no
no
Hint
Sample Explanation
The first subtask corresponds to the example in the statement. In the second subtask, there is no die C that can make the set non-transitive. Similarly, the answer for the third subtask is also no.
Translated by ChatGPT 5