A13152 | Almost Same Distance
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Let $G$ be a simple graph. Let $W$ be a non-empty subset of vertices. Then $W$ is almost- $k$ -uniform if for each pair of distinct vertices $u,v \in W$ the distance between $u$ and $v$ is either $k$ or $k+1$ .
You are given a tree on $n$ vertices. For each $i$ between $1$ and $n$ , find the maximum size of an almost- $i$ -uniform set.
You are given a tree on $n$ vertices. For each $i$ between $1$ and $n$ , find the maximum size of an almost- $i$ -uniform set.
输入格式
The first line contains a single integer $n$ ( $2 \leq n \leq 5 \cdot 10^5$ ) – the number of vertices of the tree.
Then $n-1$ lines follows, the $i$ -th of which consisting of two space separated integers $u_i$ , $v_i$ ( $1 \leq u_i, v_i \leq n$ ) meaning that there is an edge between vertices $u_i$ and $v_i$ .
It is guaranteed that the given graph is tree.
Then $n-1$ lines follows, the $i$ -th of which consisting of two space separated integers $u_i$ , $v_i$ ( $1 \leq u_i, v_i \leq n$ ) meaning that there is an edge between vertices $u_i$ and $v_i$ .
It is guaranteed that the given graph is tree.
输出格式
Output a single line containing $n$ space separated integers $a_i$ , where $a_i$ is the maximum size of an almost- $i$ -uniform set.
输入输出样例
输入 #1
5 1 2 1 3 1 4 4 5
输出 #1
4 3 2 1 1
输入 #2
6 1 2 1 3 1 4 4 5 4 6
输出 #2
4 4 2 1 1 1
Consider the first example.
- The only maximum almost- $1$ -uniform set is $\{1, 2, 3, 4\}$ .
- One of the maximum almost- $2$ -uniform sets is or $\{2, 3, 5\}$ , another one is $\{2, 3, 4\}$ .
- A maximum almost- $3$ -uniform set is any pair of vertices on distance $3$ .
- Any single vertex is an almost- $k$ -uniform set for $k \geq 1$ .
In the second sample there is an almost- $2$ -uniform set of size $4$ , and that is $\{2, 3, 5, 6\}$ .
- The only maximum almost- $1$ -uniform set is $\{1, 2, 3, 4\}$ .
- One of the maximum almost- $2$ -uniform sets is or $\{2, 3, 5\}$ , another one is $\{2, 3, 4\}$ .
- A maximum almost- $3$ -uniform set is any pair of vertices on distance $3$ .
- Any single vertex is an almost- $k$ -uniform set for $k \geq 1$ .
In the second sample there is an almost- $2$ -uniform set of size $4$ , and that is $\{2, 3, 5, 6\}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted