Logo
(追記) (追記ここまで)

26025번 - Berry Battle 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB75353346.479%

문제

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 $n$ vertices numbered from 1ドル$ to $n$. 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 $v,ドル all the ants that are on different vertices will walk one step towards $v$. The ants already at $v$ 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 $n$ 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 $n$ (2ドル \leq n \leq 3 \cdot 10^5$).

The following $n-1$ lines each contain two integers $u$ and $v$ (1ドル \leq u \neq v \leq n$), meaning that an edge goes between vertices $u$ and $v$.

출력

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

Otherwise, first print "YES" on one line. On the second line, print $n$ integers $p_1, p_2, \cdots , p_n,ドル the order in which to pick the berries (1ドル \leq p_i \leq n$). This means that the $i$:th berry you pick is the one in vertex $p_i$.

제한

예제 입력 1

10
1 2
2 3
3 4
3 9
3 7
7 10
1 5
5 6
1 8

예제 출력 1

YES
1 5 6 3 4 9 8 7 10 2

예제 입력 2

3
1 2
2 3

예제 출력 2

NO

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2022 B번

  • 문제를 만든 사람: Nils Gustafsson
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /