问题 C: Dominoes!

内存限制:1024 MB 时间限制:2 S
题面:Markdown 评测方式:Special Judge 上传者:
提交:10 通过:4

题目描述

Dominoes are rectangular tiles made of wood, bone, or plastic. They are arranged in a line at a certain distance from each other, and when the first tile is lightly tipped over, the rest of the tiles fall in succession, creating a chain reaction. ![](https://uploadfiles.nowcoder.com/images/20240708/0_1720440157272/79D0C5A1EFE6367EAC5BB39B5F3B4AC8) However, now you want to use the dominoes to play a different game. Given $n$ dominoes, each domino has two positive integers between $1$ and $10^9$ written on it. You need to arrange these dominoes in a horizontal line so that each end of a domino matches the end of the adjacent domino (except for the two ends of the line). When arranging the dominoes, you can choose either number to be on the left or right. The task is to determine if there is an arrangement where the numbers at the touching ends of adjacent dominoes are always different. If such an arrangement exists, provide a possible solution.

输入格式

The first line of input contains an integer $n$ $(1\leq n\leq 2\times 10^5)$, denoting the number of dominoes. Then $n$ lines follow. The $i$\-th $(1\leq i\leq n)$ line contains two integers $x_i,y_i$ $(1\leq x_i,y_i\leq 10^9)$, denoting the numbers written on the $i$\-th domino.

输出格式

If there exists a valid way to arrange dominoes, output "Yes" in the first line (without quotes). Otherwise, output \`\`No'' in the first line (without quotes). You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will all be considered as positive replies. If your answer is "Yes", you need to output two numbers $x_i, y_i$ in the next $n$ lines, where the $i$\-th ($1 \leq i \leq n$) line represents the numbers on the left and right sides of the $i$\-th domino in your solution, arranged from left to right.

输入样例 复制

3
1 2
2 3
3 1

输出样例 复制

Yes
1 2
3 2
3 1

数据范围与提示

#### 样例二 ##### 输入 ``` 3 1 1 1000000000 1000000000 1000000000 1000000000 ``` ##### 输出 ``` Yes 1000000000 1000000000 1 1 1000000000 1000000000 ``` #### 样例三 ##### 输入 ``` 2 2 2 2 2 ``` ##### 输出 ``` No ```