Jungle Game

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

요약
N x N 격자에서 서로 다른 N개의 점을 골라, 어떤 두 점의 합도 주어진 금지 쌍이 되지 않게 한다.
난이도

어려움10점 중 9점

유형
조합론, 수학, 그리디, 정수론
정답자
아직 제출이 없습니다

문제

Denise is designing a rainforest themed board game. The goal of the game is for each player to form a team of two characters and complete various challenges.

There are NN different characters numbered from 11 to NN. Each character ii has two attributes p_ip\_i and s_is\_i (problem solving skill and strength). The numbers p_ip\_i and s_is\_i are positive integers satisfying 1≤p_i,s_i≤N1 \leq p\_i, s\_i \leq N. Before the game starts, each player will pick two characters ii and jj to form a team. It is possible to pick two copies of the same character. The total problem solving skill and strength of the team will be p_i+p_jp\_i + p\_j and s_i+s_js\_i + s\_j respectively.

In the game there are also NN challenge cards numbered from 11 to NN. Each of these also has two attributes P_kP\_k and S_kS\_k. Denise has already designed the challenge cards and decided on the values of all numbers P_1,P_2,…,P_NP\_1, P\_2, \dots, P\_N and S_1,S_2,…,S_NS\_1, S\_2, \dots, S\_N. However, the rules of the game assume that it is not possible for a player to form a team whose problem solving skill and strength are both the same as one of the challenge cards. In other words, the situation

p_i+p_j=P_k and s_i+s_j=S_kp\_i+p\_j = P\_k \text{ and } s\_i+s\_j = S\_k

should never occur for any triple i,j,ki,j,k (note that ii can be equal to jj).

The only thing left to do is to decide the NN distinct pairs (p_1,s_1),(p_2,s_2)…,(p_N,s_N)(p\_1, s\_1), (p\_2, s\_2) \dots, (p\_N, s\_N) such that 1≤p_i,s_i≤N1 \leq p\_i, s\_i \leq N and the situation above never happens.

입력

The first line contains the integer NN (1≤N≤20001 \leq N \leq 2000).

The following NN lines contain the values of the challenge cards P_i,S_iP\_i, S\_i (1≤P_i,S_i≤2⋅N1 \leq P\_i, S\_i \leq 2 \cdot N).

출력

If there is no solution, print "NO". Otherwise, print "YES" followed by NN lines, each containing a pair of integers p_i,s_ip\_i, s\_i (1≤p_i,s_i≤N1 \leq p\_i, s\_i \leq N). These pairs of integers must be distinct. In other words, you may not have two indices i≠ji \neq j with p_i=p_jp\_i = p\_j and s_i=s_js\_i = s\_j.

예제2

  1. 예제 1

    입력
    5
    5 5
    5 6
    6 5
    6 6
    8 8
    
    예상 출력
    YES
    2 2
    1 1
    1 2
    2 1
    1 3
    
  2. 예제 2

    입력
    1
    2 2
    
    예상 출력
    NO