#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 XX and YY. 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 XX beats die YY if die XX is more likely than die YY to win this game.

Consider the following 4-sided dice:

Die A has numbers 44, 55, 66, and 77 on its faces.

Die B has numbers 22, 44, 55, and 1010 on its faces.

Die C has numbers 11, 44, 88, and 99 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 11 to 1010.

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 TT (1T101 \le T \le 10), the number of subtasks you need to solve.

The next TT lines each describe one subtask and contain 88 integers: the 44 face values of die A, followed by the 44 face values of die B. All values are between 11 and 1010, and are not necessarily sorted. The same number may appear multiple times, even on the same die.

Output Format

Output TT lines. If it is possible to assign numbers to die C so that the kk-th subtask becomes a non-transitive set of dice, output yes on the kk-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