| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 3 | 3 | 3 | 100.000% |
Busy Beaver has finally rage-quit Minesweeper and picked up Mahjong Connect instead. He has $N$ mahjong tiles at distinct locations on the Cartesian plane. Each tile $i$ has integer coordinates $(x_i, y_i)$ and a type $t_i$ with 1ドル \le t_i \le M$.
Two distinct tiles $i$ and $j$ match if and only if all of the following hold:
A perfect matching is a partition of the $N$ tiles into $N/2$ disjoint pairs such that every pair is a valid match under the rules above. Determine whether a perfect matching exists. If it does, output any one perfect matching; otherwise, report that no perfect matching exists.
The first line contains two integers $N$ and $M$ (2ドル\le N\le 3\cdot 10^5,ドル 1ドル\le M\le 3\cdot 10^5,ドル $N$ is even).
The next $N$ lines describe the tiles. The $i$-th of these lines contains three integers $x_i,ドル $y_i$ and $t_i$ ($|x_i|,|y_i|\le 10^9,ドル 1ドル\le t_i\le M$).
It is guaranteed that the pairs $(x_i,y_i)$ are distinct.
If no perfect matching exists, print a single line containing NO.
Otherwise, print a single line containing YES. Then print $N/2$ lines, each containing two integers $i$ and $j$ (1ドル\le i,j\le N,ドル $i\neq j$), indicating that tiles $i$ and $j$ form a matched pair.
Each index from 1ドル$ to $N$ must appear in exactly one pair. The pairs may be printed in any order, and within each pair, the order of $i$ and $j$ does not matter.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
4 2 -1 0 1 1 0 1 0 -1 2 0 1 2
YES 1 2 3 4
4 2 -1 0 1 1 0 1 0 0 2 0 1 2
NO
22 3 1 1 2 1 2 2 1 3 2 1 4 1 2 3 2 3 2 1 3 1 2 4 3 2 5 4 1 5 3 1 5 2 1 5 1 1 7 1 3 7 2 3 7 3 3 7 4 3 9 4 3 10 4 3 11 4 3 10 3 1 10 2 1 10 1 3
YES 1 7 2 3 4 9 5 8 6 11 10 12 13 22 14 15 16 17 18 19 20 21
In the first test case, we can pair up the tiles at $(-1,0),(1,0)$ and $(0,-1),(0,1),ドル respectively.
In the second test case, we cannot do the same thing because the tile at $(0,0)$ blocks the connection between $(-1,0)$ and $(1,0)$.
The visualization of the third test case is as follows (different colors represent different types of tiles):
Note again that, if the answer is YES, any valid pairing with any order will be accepted. For instance, for the first sample, the following output is also acceptable:
YES 4 3 1 2