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

15937번 - Rooks 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.4 초 1024 MB42111035.714%

문제

Consider a square board with N rows (called ranks) and N columns (called files). K of the squares are blocked by obstacles. Pieces similar to the rooks in chess are placed on this board. Two rooks are said to be attacking each other if they are on the same rank or file and there are no obstacles between them.

Given a positive integer N and the positions of the K obstacles, place as many rooks as possible on the board so that no two rooks attack each other.

입력

The first line of the input contains N and K, separated by a space. Each of the following K lines contain a pair of numbers r and f, separated by a space describing the rank and file of an obstacle. All the obstacles are distinct.

출력

The first line of the output must contain a single number S, the highest number of non-attacking rooks that the table can accommodate. Each of the following S lines must contain a pair of numbers r and f, separated by a space, showing the rank and file of a rook. Any correct placement of S rooks will be accepted.

제한

  • 1 ≤ N ≤ 1,000
  • 1 ≤ K ≤ min(N2, 2,000)
  • Ranks and files are numbered from 1 to N.

예제 입력 1

5 2
3 2
2 4

예제 출력 1

7
1 4
2 2
2 5
3 1
3 4
4 3
5 2

힌트

출처

Olympiad > Romanian Master of Informatics > Romanian Master of Informatics 2014 2번

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

출처

대학교 대회

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

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