한 번에 하나씩 추가되어 마지막에 루트 있는 트리가 되는 간선들이 주어질 때, 각 단계의 도달 가능 집합이 모두 연속된 정수 구간이 되도록 번호를 매긴다.
어려움8트리DFS동적 계획법아직 제출이 없습니다시간 제한3초메모리 제한512 MBConsider a set V=1,…,n of n vertices, and a sequence of directed edges e_1,…,e_n−1. Let G_0,…,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,…,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,…,p_n of the set 1,…,n. Let S\_i(v) = \\{p\_u \mid u can be reached from v in G\_i\\}. A permutation p_1,…,p_n is called suitable if for any i∈0,…,n−1 and for any v∈V we have that S_i(v) consists of consecutive numbers (that is, S_i(v)=l,l+1,…,r for some numbers l and r).
The first line contains a single integer n (2≤n≤106).
The next n−1 lines describe the edges e_1,…,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≤u_i,v_i≤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,…,p_n describing any suitable permutation.