CF1041E Tree Reconstruction

题目描述

有一棵树,现在给你每条树边被去掉时,形成的两个联通块中点的最大的编号分别是多少,问满足条件的树存不存在,若存在请给出构造。

输入格式

第一行一个整数 $n$($2\le n\le1000$)。 往下 $n-1$ 行,每行两个整数 $a_i$ 和 $b_i$($1\le a_i

输出格式

如果不存在满足条件的树,输出 `NO`。 否则输出 `YES`,下面 $n-1$ 行每行描述一条树边(两端点的编号)。

说明/提示

Possible tree from the first example. Dotted lines show edges you need to remove to get appropriate pairs. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1041E/e43409cf3b42ae3836668f440853ef93e1fdf9b6.png)