Codeforces Round 866 (Div. 1)
C
The Fox and the Complete Tree Traversal
Codeforces
2400
原题
← BD →
翻译中…

The fox Yae climbed the tree of the Sacred Sakura. A tree is a connected undirected graph that does not contain cycles.

翻译中…

The fox uses her magical powers to move around the tree. Yae can jump from vertex $v$ to another vertex $u$ if and only if the distance between these vertices does not exceed $2$. In other words, in one jump Yae can jump from vertex $v$ to vertex $u$ if vertices $v$ and $u$ are connected by an edge, or if there exists such vertex $w$ that vertices $v$ and $w$ are connected by an edge, and also vertices $u$ and $w$ are connected by an edge.

翻译中…

After Yae was able to get the sakura petal, she wondered if there was a cyclic route in the tree $v_1, v_2, \ldots, v_n$ such that:

翻译中…
  • the fox can jump from vertex $v_i$ to vertex $v_{i + 1}$,
  • the fox can jump from vertex $v_n$ to vertex $v_1$,
  • all $v_i$ are pairwise distinct.
翻译中…

Help the fox determine if the required traversal exists.

翻译中…

Input

翻译中…

The first line contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) —the number of vertices of the tree.

翻译中…

Each of the following $n - 1$ lines contains two integers $u$ and $v$ ($1 \le u, v \le n$, $u \ne v$) — vertices connected by an edge. It is guaranteed that these edges form a tree.

翻译中…

Output

翻译中…

On the first line, print "Yes" (without quotes) if the required route of the tree exists, or "No" (without quotes) otherwise.

翻译中…

If the required tree traversal exists, on the second line print $n$ integers of different integers $v_1, v_2, \ldots, v_n$ ($1 \le v_i \le n$) — the vertices of the tree in traversal order.

翻译中…

If there are several correct traversals, output any of them.

翻译中…

Note

翻译中…

The tree from the first example is shown below. The bold arrows indicate the fox's route.

翻译中…

image

翻译中…

In the second example, any sequence of three different vertices is a correct route, because the fox can jump from any vertex to any vertex.

翻译中…

The tree from the third example is shown below. It can be shown that there is no required route for it.

翻译中…

image

翻译中…

样例

Input #1
5
1 2
1 3
3 4
3 5
Output #1
Yes
4 5 1 2 3
InputCopy OutputCopy
Input #2
3
1 2
1 3
Output #2
Yes
1 2 3
InputCopy OutputCopy
Input #3
15
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
5 10
5 11
6 12
6 13
7 14
7 15
Output #3
No
InputCopy OutputCopy
题目信息
题号
1819C
时间限制
1 s
内存限制
256 MB
标签
构造
动态规划
模拟
数学
树

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