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

27633번 - Concealed Domino 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB479822.222%

문제

There are N dominoes. Each domino is an ordered-pair of two eyes (ai, bi) where 1 ≤ ai, bi ≤ M. That means a domino (p, q) differs from a domino (q, p) if p ≠ q.

Due to some unknown reasons, each domino is either partially or fully concealed. Specifically, at least an eye is concealed from each domino.

Your task in this problem is to figure out the concealed eyes such that no two dominoes are the same. If it is possible, then you need to output one set of unconcealed dominoes that corresponds to the given input.

For example, let there be N = 3 dominoes with the maximum value of an eye be M = 2 and the dominoes be {(?, ?),(1, ?),(?, 2)}. There are 6 correct answers for this case.

  • {(1, 1),(1, 2),(2, 2)}
  • {(1, 2),(1, 1),(2, 2)}
  • {(2, 1),(1, 1),(1, 2)}
  • {(2, 1),(1, 1),(2, 2)}
  • {(2, 1),(1, 2),(2, 2)}
  • {(2, 2),(1, 1),(1, 2)}

Note that answers such as {(1, 1),(1, 1),(1, 2)} is not correct as the first and second dominoes are the same. Answer such as {(1, 1),(2, 2),(1, 2)} is also not correct as the second domino (2, 2) does not correspond to the input (1, ?).

입력

Input begins with a line containing two integers N M (1 ≤ N ≤ min(100 000, M2); 1 ≤ M ≤ 100, 000) representing the number of dominoes and the maximum value on each eye. The next N lines each contains two integers ai bi (ai, bi ∈ {−1, 1, 2, . . . , M}; ai = −1 or bi = −1) representing the ordered-pair of eyes of the ith domino. If ai or bi equals to −1, then it means the respective value is unknown.

출력

If all concealed eyes can be determined such that no two dominoes are the same, then output starts with “YES” (without quotes) in a line. The next N lines each contains two integers pi qi representing the ordered-pair of eyes of the ith domino. The order of dominoes in the output should be the same as the input. If there is more than one correct answer, you may output any one of them.

If the concealed eyes cannot be determined, then output “NO” (without quotes) in a line.

제한

예제 입력 1

3 2
-1 -1
1 -1
-1 2

예제 출력 1

YES
1 1
1 2
2 2

예제 입력 2

3 2
1 -1
1 -1
1 -1

예제 출력 2

NO

예제 입력 3

3 3
1 -1
1 -1
1 -1

예제 출력 3

YES
1 1
1 2
1 3

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2021 L번

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

출처

대학교 대회

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

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