#arc175d. D - LIS on Tree 2
D - LIS on Tree 2
Score: points
问题陈述
有一棵包含 个顶点的树,顶点编号为 到 。树中的第 条边双向连接了顶点 和 。
对于一个排列 ,我们定义 如下:
- 对于每个顶点 ,设 是从顶点 到顶点 的简单路径,设 是 的最长递增子序列的长度。我们定义 。
给定一个整数 。确定是否存在一个排列 使得 。如果存在,请展示这样一个排列。
什么是最长递增子序列?一个序列的子序列是通过从原始序列中移除零个或多个元素,并连接剩余元素而不改变顺序得到的序列。例如, 是 的一个子序列,但 不是。 一个序列的最长递增子序列是该序列中最长的严格递增子序列。什么是简单路径?对于图 中的顶点 和 ,从顶点 到顶点 的路径是一系列顶点 ,使得 ,,并且对于所有 , 和 由一条边连接。此外,如果 都是不同的,它被称为从顶点 到顶点 的简单路径(或简称路径)。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is a tree with vertices numbered to . The -th edge of the tree connects vertices and bidirectionally.
For a permutation of , we define as follows:
- For each vertex , let be the simple path from vertex to vertex , and let be the length of a longest increasing subsequence of . We define .
You are given an integer . Determine whether there is a permutation of such that . 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, is a subsequence of , but 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 and in a graph , a walk from vertex to vertex is a sequence of vertices such that , , and and are connected by an edge for all . Furthermore, if are all distinct, it is called a simple path (or simply a path) from vertex to vertex .
Constraints
- All input values are integers.
- The given graph is a tree.
Input
The input is given from Standard Input in the following format:
Output
If there is no permutation such that , print No
.
If there is a permutation such that , print it in the following format:
Yes
If multiple permutations 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 , then is determined as follows:
-
The simple path from vertex to vertex is , and the length of the longest increasing subsequence of is . Thus, .
-
The simple path from vertex to vertex is , and the length of the longest increasing subsequence of is . Thus, .
-
The simple path from vertex to vertex is , and the length of the longest increasing subsequence of is . Thus, .
-
The simple path from vertex to vertex is , and the length of the longest increasing subsequence of is . Thus, .
-
The simple path from vertex to vertex is , and the length of the longest increasing subsequence of is . Thus, .
-
From the above, .
Hence, the permutation in the sample output satisfies the condition . Besides, 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 satisfies .
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