Logo
(追記) (追記ここまで)

28209번 - Classical Maximization Problem 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB80262332.857%

문제

You are given 2ドルn$ distinct points on a plane. Point $i$ has integer coordinates $(x_i, y_i)$.

Points $i$ and $j$ are a friendly pair if either $x_i = x_j$ or $y_i = y_j$.

Form $n$ pairs of points. Every point must belong to exactly one pair. The number of friendly pairs among your $n$ pairs must be maximized.

입력

Each test contains multiple test cases. The first line contains the number of test cases $t$ (1ドル \le t \le 10^4$). The description of the test cases follows.

The first line of each test case contains a single integer $n$ (1ドル \le n \le 10^5$).

The $i$-th of the next 2ドルn$ lines contains two integers $x_i$ and $y_i,ドル denoting the coordinates of the $i$-th point ($-10^9 \le x_i, y_i \le 10^9$). All points are distinct.

It is guaranteed that the sum of $n$ over all test cases does not exceed 10ドル^5$.

출력

For each test case, print a non-negative integer $k,ドル denoting the maximum possible number of friendly pairs.

In the $i$-th of the next $n$ lines, print two integers $a_i$ and $b_i,ドル denoting a pair formed by points $a_i$ and $b_i$ (1ドル \le a_i, b_i \le 2n$; $a_i \ne b_i$).

Every integer from 1ドル$ to 2ドルn$ must appear among $a_i$ and $b_i$ exactly once. The number of indices $i$ such that points $a_i$ and $b_i$ are a friendly pair must be equal to $k$.

제한

예제 입력 1

3
2
0 0
0 1
1 0
1 1
2
0 0
0 1
0 2
0 3
2
0 0
1 1
2 2
3 3

예제 출력 1

2
2 4
3 1
2
4 3
2 1
0
1 2
3 4

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2023 > Day 7: Gennady Korotkevich Contest 7 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /