CF1266F.Almost Same Distance

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let GG be a simple graph. Let WW be a non-empty subset of vertices. Then WW is almost-kk-uniform if for each pair of distinct vertices u,v∈Wu,v \in W the distance between uu and vv is either kk or k+1k+1.

You are given a tree on nn vertices. For each ii between 11 and nn, find the maximum size of an almost-ii-uniform set.

设 GG 是一个简单图,WW 是顶点集的一个非空子集。若对任意两个不同的顶点 u,v∈Wu,v \in W,uu 与 vv 之间的距离均为 kk 或 k+1k+1,则称 WW 是几乎-kk-均匀集(almost-kk-uniform set)。

给定一棵含 nn 个顶点的树。对每个 ii(1≤i≤n1 \le i \le n),求几乎-ii-均匀集的最大大小。

输入格式

The first line contains a single integer nn (2≤n≤5⋅1052 \leq n \leq 5 \cdot 10^5) – the number of vertices of the tree.

Then n−1n-1 lines follows, the ii-th of which consisting of two space separated integers uiu_i, viv_i (1≤ui,vi≤n1 \leq u_i, v_i \leq n) meaning that there is an edge between vertices uiu_i and viv_i.

It is guaranteed that the given graph is tree.

第一行包含一个整数 nn(2≤n≤5⋅1052 \leq n \leq 5 \cdot 10^5),表示树的顶点数。

接下来是 n−1n-1 行,其中第 ii 行包含两个用空格分隔的整数 uiu_i 和 viv_i(1≤ui,vi≤n1 \leq u_i, v_i \leq n),表示顶点 uiu_i 与 viv_i 之间存在一条边。

保证所给图是一棵树。

输出格式

Output a single line containing nn space separated integers aia_i, where aia_i is the maximum size of an almost-ii-uniform set.

输出一行,包含 nn 个以空格分隔的整数 aia_i,其中 aia_i 表示一个几乎-ii-一致集合的最大大小。

输入输出样例

  • 输入#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-11-uniform set is 1,2,3,4{1, 2, 3, 4}.
  • One of the maximum almost-22-uniform sets is or 2,3,5{2, 3, 5}, another one is 2,3,4{2, 3, 4}.
  • A maximum almost-33-uniform set is any pair of vertices on distance 33.
  • Any single vertex is an almost-kk-uniform set for k≥1k \geq 1.

In the second sample there is an almost-22-uniform set of size 44, and that is 2,3,5,6{2, 3, 5, 6}.

考虑第一个样例。

  • 唯一的极大几乎-11-均匀集是 {1,2,3,4}\{1, 2, 3, 4\}。
  • 一个极大几乎-22-均匀集是 {2,3,5}\{2, 3, 5\},另一个是 {2,3,4}\{2, 3, 4\}。
  • 任意两个距离为 33 的顶点构成一个极大几乎-33-均匀集。
  • 任意单个顶点对于所有 k≥1k \geq 1 均构成一个几乎-kk-均匀集。

在第二个样例中,存在一个大小为 44 的几乎-22-均匀集,即 {2,3,5,6}\{2, 3, 5, 6\}。

输入解题思路,AI测评打分。不知道怎么写?

首页