CF1039D.You Are Given a Tree

省选/NOI-

通过率:0%

时间限制:7.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

A tree is an undirected graph with exactly one simple path between each pair of vertices. We call a set of simple paths kk-valid if each vertex of the tree belongs to no more than one of these paths (including endpoints) and each path consists of exactly kk vertices.

You are given a tree with nn vertices. For each kk from 11 to nn inclusive find what is the maximum possible size of a kk-valid set of simple paths.

树是任意两个顶点之间恰好存在一条简单路径的无向图。我们称一组简单路径为 kk-合法 的,当且仅当:树中的每个顶点至多属于其中一条路径(端点也计入),且每条路径恰好包含 kk 个顶点。

给定一棵含 nn 个顶点的树。对每个从 11 到 nn(含)的 kk,求 kk-合法的简单路径集合的最大可能大小。

输入格式

The first line of the input contains a single integer nn (2≤n≤100 0002 \le n \le 100\,000) — the number of vertices in the tree.

Then following n−1n - 1 lines describe the tree, each of them contains two integers vv, uu (1≤v,u≤n1 \le v, u \le n) — endpoints of the corresponding edge.

It is guaranteed, that the given graph is a tree.

输入的第一行包含一个整数 nn(2≤n≤100 0002 \le n \le 100\,000)——树中顶点的数量。

接下来的 n−1n - 1 行描述该树,每行包含两个整数 vv、uu(1≤v,u≤n1 \le v, u \le n)——对应边的两个端点。

保证给定的图是一棵树。

输出格式

Output nn numbers, the ii-th of which is the maximum possible number of paths in an ii-valid set of paths.

输出 nn 个数,其中第 ii 个数表示一个 ii-合法路径集合中可能包含的路径的最大数目。

输入输出样例

  • 输入#1

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

    输出#1

    7
    3
    2
    1
    1
    1
    1
  • 输入#2

    6
    1 2
    2 3
    2 4
    1 5
    5 6

    输出#2

    6
    2
    2
    1
    1
    0

说明/提示

One way to achieve the optimal number of paths for the second sample is illustrated in the following picture:

实现第二个样例的最优路径数的一种方法如下图所示:

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

首页