#abc240e. E - Ranges on Tree
E - Ranges on Tree
Score : points
问题描述
给定一棵有 个顶点的根树,其中根节点为顶点 。
对于每个 ,第 条边连接顶点 和顶点 。
对于每个 ,令 表示以顶点 为根的子树中所有顶点的集合。(每个顶点都在以其自身为根的子树中,即 。)
另外,对于整数 和 ,令 表示从 到 之间的所有整数集合,即 。
考虑一个由 对整数组成的序列 $\big((L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N)\big)$,满足以下条件:
- 对于每一个整数 (满足 ),都有 。
- 对于每一对整数 (满足 ),满足以下情况:
- 若 ,则有 ;
- 若 ,则有 。
可以证明至少存在一个序列 $\big((L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N)\big)$。在这些序列中,找出并输出一个使得 $\max \lbrace L_1, L_2, \ldots, L_N, R_1, R_2, \ldots, R_N \rbrace$ 达到最小值的序列,即使用的最大整数最小化。(如果有多个这样的序列,你可以任选其中一个打印。)
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a rooted tree with vertices. The root is Vertex .
For each , the -th edge connects Vertex and Vertex .
For each , let denote the set of all vertices in the subtree rooted at Vertex . (Each vertex is in the subtree rooted at itself, that is, .)
Additionally, for integers and , let denote the set of all integers between and , that is, .
Consider a sequence of pairs of integers $\big((L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N)\big)$ that satisfies the conditions below.
- for every integer such that .
- The following holds for every pair of integers such that .
- if
- if
It can be shown that there is at least one sequence $\big((L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N)\big)$. Among those sequences, print one that minimizes $\max \lbrace L_1, L_2, \ldots, L_N, R_1, R_2, \ldots, R_N \rbrace$, the maximum integer used. (If there are multiple such sequences, you may print any of them.)
Constraints
- All values in input are integers.
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print lines in the format below. That is, for each , the -th line should contain and separated by a space.
Sample Input 1
3
2 1
3 1
Sample Output 1
1 2
2 2
1 1
$(L_1, R_1) = (1, 2), (L_2, R_2) = (2, 2), (L_3, R_3) = (1, 1)$ satisfies the conditions.
Indeed, we have $[L_2, R_2] \subseteq [L_1, R_1], [L_3, R_3] \subseteq [L_1, R_1], [L_2, R_2] \cap [L_3, R_3] = \emptyset$.
Additionally, $\max \lbrace L_1, L_2, L_3, R_1, R_2, R_3 \rbrace = 2$ is the minimum possible value.
Sample Input 2
5
3 4
5 4
1 2
1 4
Sample Output 2
1 3
3 3
2 2
1 2
1 1
Sample Input 3
5
4 5
3 2
5 2
3 1
Sample Output 3
1 1
1 1
1 1
1 1
1 1
update @ 2024/3/10 10:21:31