#arc175d. D - LIS on Tree 2

D - LIS on Tree 2

Score: 700700 points

问题陈述

有一棵包含 NN 个顶点的树,顶点编号为 11NN。树中的第 ii 条边双向连接了顶点 uiu_iviv_i

对于一个排列 P=(P1,,PN)P=(P_1,\ldots,P_N),我们定义 f(P)f(P) 如下:

  • 对于每个顶点 i (1iN)i\ (1\leq i\leq N),设 (v1=1,v2,,vk=i)(v_1=1,v_2,\ldots,v_k=i) 是从顶点 11 到顶点 ii 的简单路径,设 LiL_i(Pv1,Pv2,,Pvk)(P_{v_1},P_{v_2},\ldots,P_{v_k}) 的最长递增子序列的长度。我们定义 f(P)=i=1NLif(P) = \sum_{i=1}^N L_i

给定一个整数 KK。确定是否存在一个排列 PP 使得 f(P)=Kf(P)=K。如果存在,请展示这样一个排列。

什么是最长递增子序列?一个序列的子序列是通过从原始序列中移除零个或多个元素,并连接剩余元素而不改变顺序得到的序列。例如,(10,30)(10,30)(10,20,30)(10,20,30) 的一个子序列,但 (20,10)(20,10) 不是。 一个序列的最长递增子序列是该序列中最长的严格递增子序列。什么是简单路径?对于图 GG 中的顶点 XXYY,从顶点 XX 到顶点 YY路径是一系列顶点 (v1,v2,,vk)(v_1,v_2, \ldots, v_k),使得 v1=Xv_1=Xvk=Yv_k=Y,并且对于所有 1ik11\leq i\leq k-1viv_ivi+1v_{i+1} 由一条边连接。此外,如果 v1,v2,,vkv_1,v_2, \ldots, v_k 都是不同的,它被称为从顶点 XX 到顶点 YY简单路径(或简称路径)。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There is a tree with NN vertices numbered 11 to NN. The ii-th edge of the tree connects vertices uiu_i and viv_i bidirectionally.

For a permutation P=(P1,,PN)P=(P_1,\ldots,P_N) of (1,,N)(1,\ldots,N), we define f(P)f(P) as follows:

  • For each vertex i (1iN)i\ (1\leq i\leq N), let (v1=1,v2,,vk=i)(v_1=1,v_2,\ldots,v_k=i) be the simple path from vertex 11 to vertex ii, and let LiL_i be the length of a longest increasing subsequence of (Pv1,Pv2,,Pvk)(P_{v_1},P_{v_2},\ldots,P_{v_k}). We define f(P)=i=1NLif(P) = \sum_{i=1}^N L_i.

You are given an integer KK. Determine whether there is a permutation PP of (1,,N)(1,\ldots,N) such that f(P)=Kf(P)=K. If it exists, present one such permutation.

What is a longest increasing subsequence? A subsequence of a sequence is a sequence obtained by removing zero or more elements from the original sequence and concatenating the remaining elements without changing the order. For example, (10,30)(10,30) is a subsequence of (10,20,30)(10,20,30), but (20,10)(20,10) is not.
The longest increasing subsequence of a sequence is the longest strictly increasing subsequence of that sequence. What is a simple path? For vertices XX and YY in a graph GG, a walk from vertex XX to vertex YY is a sequence of vertices (v1,v2,,vk)(v_1,v_2, \ldots, v_k) such that v1=Xv_1=X, vk=Yv_k=Y, and viv_i and vi+1v_{i+1} are connected by an edge for all 1ik11\leq i\leq k-1. Furthermore, if v1,v2,,vkv_1,v_2, \ldots, v_k are all distinct, it is called a simple path (or simply a path) from vertex XX to vertex YY.

Constraints

  • All input values are integers.
  • 2N2×1052 \leq N \leq 2\times 10^5
  • 1K10111\leq K \leq 10^{11}
  • 1ui,viN1\leq u_i,v_i\leq N
  • The given graph is a tree.

Input

The input is given from Standard Input in the following format:

NN KK

u1u_1 v1v_1

\vdots

uN1u_{N-1} vN1v_{N-1}

Output

If there is no permutation PP such that f(P)=Kf(P)=K, print No.

If there is a permutation PP such that f(P)=Kf(P)=K, print it in the following format:

Yes

P1P_1 \ldots PNP_N

If multiple permutations PP satisfy the condition, any of them will be accepted.

Sample Input 1

5 8
1 2
2 3
2 4
4 5

Sample Output 1

Yes
3 2 1 4 5

If P=(3,2,1,4,5)P=(3,2,1,4,5), then f(P)f(P) is determined as follows:

  • The simple path from vertex 11 to vertex 11 is (1)(1), and the length of the longest increasing subsequence of (P1)=(3)(P_1)=(3) is 11. Thus, L1=1L_1 = 1.

  • The simple path from vertex 11 to vertex 22 is (1,2)(1,2), and the length of the longest increasing subsequence of (P1,P2)=(3,2)(P_1,P_2)=(3,2) is 11. Thus, L2=1L_2 = 1.

  • The simple path from vertex 11 to vertex 33 is (1,2,3)(1,2,3), and the length of the longest increasing subsequence of (P1,P2,P3)=(3,2,1)(P_1,P_2,P_3)=(3,2,1) is 11. Thus, L3=1L_3 = 1.

  • The simple path from vertex 11 to vertex 44 is (1,2,4)(1,2,4), and the length of the longest increasing subsequence of (P1,P2,P4)=(3,2,4)(P_1,P_2,P_4)=(3,2,4) is 22. Thus, L4=2L_4 = 2.

  • The simple path from vertex 11 to vertex 55 is (1,2,4,5)(1,2,4,5), and the length of the longest increasing subsequence of (P1,P2,P4,P5)=(3,2,4,5)(P_1,P_2,P_4,P_5)=(3,2,4,5) is 33. Thus, L5=3L_5 = 3.

  • From the above, f(P)=1+1+1+2+3=8f(P)=1+1+1+2+3= 8.

Hence, the permutation PP in the sample output satisfies the condition f(P)=8f(P)=8. Besides, P=(3,2,4,5,1)P=(3,2,4,5,1) also satisfies the condition, for example.

Sample Input 2

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

Sample Output 2

No

It can be proved that no permutation PP satisfies f(P)=21f(P) = 21.

Sample Input 3

8 20
3 1
3 8
7 1
7 5
3 2
6 5
4 7

Sample Output 3

Yes
2 1 3 5 6 8 4 7