아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Berry Battle

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

요약
각 정점에 열매 하나와 개미 한 마리가 있는 나무에서, 열매를 따는 동안 모든 개미가 한 정점에 모이지 않도록 정점 순서를 정한다.
난이도

보통10점 중 7점

유형
트리, 그리디, DFS
정답자
아직 제출이 없습니다

문제

Berry picking is hard work, but also a peaceful and relaxing experience. After a long day of picking, it is common to see nothing but berries once you close your eyes to sleep. As your mind drifts into unconciousness, the berries will start living their own life and create all kinds of absurd scenarios.

You are given a tree with nn vertices numbered from 11 to nn. Initially, there is one berry in each vertex. There is also one ant in each vertex, guarding the berries. When picking the berry at vertex vv, all the ants that are on different vertices will walk one step towards vv. The ants already at vv will stay where they are. Note that since the graph is a tree, there is always one unique path the ants will take.

Your goal is to pick all the berries in the tree. The ants are no danger to you as long as they stay separated. But if at any point all the nn ants end up in the same vertex, they will attack you. Find a permutation of the vertices, so that if you pick the berries in that order, all the ants will not end up in the same vertex.

입력

The first line contains an integer nn (2≤n≤3⋅1052 \leq n \leq 3 \cdot 10^5).

The following n−1n-1 lines each contain two integers uu and vv (1≤u≠v≤n1 \leq u \neq v \leq n), meaning that an edge goes between vertices uu and vv.

출력

If it is impossible to find an answer, print "NO".

Otherwise, first print "YES" on one line. On the second line, print nn integers p_1,p_2,⋯ ,p_np\_1, p\_2, \cdots , p\_n, the order in which to pick the berries (1≤p_i≤n1 \leq p\_i \leq n). This means that the ii:th berry you pick is the one in vertex p_ip\_i.

예제2

  1. 예제 1

    입력
    10
    1 2
    2 3
    3 4
    3 9
    3 7
    7 10
    1 5
    5 6
    1 8
    
    예상 출력
    YES
    1 5 6 3 4 9 8 7 10 2
    
  2. 예제 2

    입력
    3
    1 2
    2 3
    
    예상 출력
    NO