GUPTA MECHANICAL

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

Sunday, 10 July 2022

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

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

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

Input

The first line contains a single integer t (1t104) — 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 (2n2105) — the number of dominoes.








The next n lines contain pairs of numbers ai and bi (1ai,bin) describing the numbers on the i-th domino.

It is guaranteed that the sum of n over all test cases does not exceed 2105.

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).

No comments:

Post a Comment