[Solution] Split Into Two Sets Codeforces Solution
Polycarp was recently given a set of (number — even) dominoes. Each domino contains two integers from to .
Can he divide all the dominoes into two sets so that all the numbers on the dominoes of each set are different? Each domino must go into exactly one of the two sets.
For example, if he has dominoes: , , and , then Polycarp will be able to divide them
into two sets in the required way. The first set can include the first and third dominoes ( and ), and the second set — the second and fourth ones ( and ).
The first line contains a single integer () — the number of test cases.
The descriptions of the test cases follow.
The first line of each test case contains a single even integer () — the number of dominoes.
The next lines contain pairs of numbers and () describing the numbers on the -th domino.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case print:
- YES, if it is possible to divide dominoes into two sets so that the numbers on the dominoes of each set are different;
- NO if this is not possible.
You can print YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer).
No comments:
Post a Comment