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

18970번 - Emerging Tree 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB93131012.195%

문제

Consider a set $V = \{1, \ldots, n\}$ of $n$ vertices, and a sequence of directed edges $e_1, \ldots, e_{n - 1}$. Let $G_0, \ldots, G_{n - 1}$ be a sequence of graphs such that $G_0$ is empty, and $G_i$ is obtained by introducing the edge $e_i$ into $G_{i - 1}$ for each $i = 1, \ldots, n - 1$. It is guaranteed that $G_{n - 1}$ is a rooted tree with all edges directed away from the root.

Your task is to find a suitable permutation $p_1, \ldots, p_n$ of the set $\{1, \ldots, n\}$. Let $S_i(v) = \{p_u \mid u$ can be reached from $v$ in $G_i\}$. A permutation $p_1, \ldots, p_n$ is called suitable if for any $i \in \{0, \ldots, n - 1\}$ and for any $v \in V$ we have that $S_i(v)$ consists of consecutive numbers (that is, $S_i(v) = \{l, l + 1, \ldots, r\}$ for some numbers $l$ and $r$).

입력

The first line contains a single integer $n$ (2ドル \leq n \leq 10^6$).

The next $n - 1$ lines describe the edges $e_1, \ldots, e_{n - 1}$. The $i$-th of these lines contains two integers $u_i$ and $v_i$ --- indices of the source and the target vertices of the edge $e_i$ (1ドル \le u_i, v_i \le n$).

It is guaranteed that adding all $n - 1$ edges results in a rooted tree with edges directed away from the root.

출력

If there is no suitable permutation, print the only word "No" in the only line.

Otherwise, print "Yes" on the first line. On the second line print $n$ integers $p_1, \ldots, p_n$ describing any suitable permutation.

제한

예제 입력 1

4
3 1
1 4
1 2

예제 출력 1

Yes
3 1 4 2

예제 입력 2

7
1 2
1 3
1 4
2 5
3 6
4 7

예제 출력 2

No

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2018 > Day 3: MIPT Contest E번

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

출처

대학교 대회

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

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