Codeforces Round 509 (Div. 2)
E
Tree Reconstruction
Codeforces
1900
原题
← DF →
翻译中…

Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from $1$ to $n$. For every edge $e$ of this tree, Monocarp has written two numbers: the maximum indices of the vertices of the two components formed if the edge $e$ (and only this edge) is erased from the tree.

翻译中…

Monocarp has given you a list of $n - 1$ pairs of numbers. He wants you to provide an example of a tree that will produce the said list if this tree exists. If such tree does not exist, say so.

翻译中…

Input

翻译中…

The first line contains one integer $n$ ($2 \le n \le 1\,000$) — the number of vertices in the tree.

翻译中…

Each of the next $n-1$ lines contains two integers $a_i$ and $b_i$ each ($1 \le a_i \lt b_i \le n$) — the maximal indices of vertices in the components formed if the $i$-th edge is removed.

翻译中…

Output

翻译中…

If there is no such tree that can produce the given list of pairs, print "NO" (without quotes).

翻译中…

Otherwise print "YES" (without quotes) in the first line and the edges of the tree in the next $n - 1$ lines. Each of the last $n - 1$ lines should contain two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$) — vertices connected by an edge.

翻译中…

Note: The numeration of edges doesn't matter for this task. Your solution will be considered correct if your tree produces the same pairs as given in the input file (possibly reordered). That means that you can print the edges of the tree you reconstructed in any order.

翻译中…

Note

翻译中…

Possible tree from the first example. Dotted lines show edges you need to remove to get appropriate pairs.

翻译中…

image

翻译中…

样例

Input #1
4
3 4
1 4
3 4
Output #1
YES
1 3
3 2
2 4
InputCopy OutputCopy
Input #2
3
1 3
1 3
Output #2
NO
InputCopy OutputCopy
Input #3
3
1 2
2 3
Output #3
NO
InputCopy OutputCopy
题目信息
题号
1041E
时间限制
1 s
内存限制
256 MB
标签
构造
数据结构
图论
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。