아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Concealed Domino

시간 제한1초메모리 제한1024 MB

요약
N개의 도미노에서 -1로 가려진 눈을 채워 모든 도미노가 서로 다르고 각 완성된 쌍이 입력 패턴과 일치하도록 만든다.
난이도

보통10점 중 6점

유형
그래프, 백트래킹, 그리디
정답자
아직 제출이 없습니다

문제

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.

예제3

  1. 예제 1

    입력
    3 2
    -1 -1
    1 -1
    -1 2
    
    예상 출력
    YES
    1 1
    1 2
    2 2
    
  2. 예제 2

    입력
    3 2
    1 -1
    1 -1
    1 -1
    
    예상 출력
    NO
    
  3. 예제 3

    입력
    3 3
    1 -1
    1 -1
    1 -1
    
    예상 출력
    YES
    1 1
    1 2
    1 3