#P15775. [JAG 2025 Summer Camp #2] Hanako' s Art II
[JAG 2025 Summer Camp #2] Hanako' s Art II
题目描述
There are points in the -plane. Any two points have neither the same -coordinate nor the same -coordinate. Each point has a color represented by an integer between and (inclusive). For each of the colors, there are exactly two points of that color.
An artist, Hanako, is willing to create a masterpiece by drawing polygonal chains in the -plane. According to her aesthetic sense, a masterpiece must satisfy all the following conditions.
- Any two points having the same color are the endpoints of one of the polygonal chains.
- Each polygonal chain consists of exactly two line segments, each of which is parallel to the - or -axis.
- No two polygonal chains intersect.
Your task is to determine whether Hanako can create such a masterpiece.
输入格式
The input consists of multiple test cases. The first line of input contains an integer () representing the number of test cases. After that, test cases follow. Each of them is given in the following format.
$$\begin{aligned} & n \\ & y_1 \ c_1 \\ & \vdots \\ & y_{2n} \ c_{2n} \end{aligned} $$The first line contains an integer () representing the number of polygonal chains which Hanako has to draw. Each of the following lines contains two integers and satisfying and . Each line represents that the -th point has the coordinate and the color .
It is guaranteed that if . In addition, no three points have the same color.
The sum of over all the test cases does not exceed .
输出格式
If Hanako can create a masterpiece, print "Yes"; otherwise, print "No".
2
3
2 1
1 2
4 3
6 1
3 3
5 2
3
2 3
6 1
5 2
1 1
4 3
3 2
Yes
No
提示
One of the possible masterpieces in Sample Input 1 is depicted in Figure J-1.
:::align{center}

Figure J-1: Illustration of Sample Input 1 :::