## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Split Into Two Sets Codeforces Solution

E. Split Into Two Sets
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp was recently given a set of $n$ (number $n$ — even) dominoes. Each domino contains two integers from $1$ to $n$.

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 $4$ dominoes: $\left\{1,4\right\}$$\left\{1,3\right\}$$\left\{3,2\right\}$ and $\left\{4,2\right\}$, then Polycarp will be able to divide them

Solution Click Below:-  👉
👇👇👇👇👇

into two sets in the required way. The first set can include the first and third dominoes ($\left\{1,4\right\}$ and $\left\{3,2\right\}$), and the second set — the second and fourth ones ($\left\{1,3\right\}$ and $\left\{4,2\right\}$).

Input

The first line contains a single integer $t$ ($1\le t\le {10}^{4}$) — the number of test cases.

The descriptions of the test cases follow.

The first line of each test case contains a single even integer $n$ ($2\le n\le 2\cdot {10}^{5}$) — the number of dominoes.

The next $n$ lines contain pairs of numbers ${a}_{i}$ and ${b}_{i}$ ($1\le {a}_{i},{b}_{i}\le n$) describing the numbers on the $i$-th domino.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot {10}^{5}$.

Output

For each test case print:

• YES, if it is possible to divide $n$ 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 yEsyesYes and YES will be recognized as a positive answer).