| MITIT Winter 2025-26 Beginner Round |
|---|
| Закончено |
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 11 0 10 -1 20 1 2
YES 1 2 3 4
4 2-1 0 11 0 10 0 20 1 2
NO
22 31 1 21 2 21 3 21 4 12 3 23 2 13 1 24 3 25 4 15 3 15 2 15 1 17 1 37 2 37 3 37 4 39 4 310 4 311 4 310 3 110 2 110 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
| Название |
|---|


