CF1805D.A Wide, Wide Graph

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a tree (a connected graph without cycles) with nn vertices.

Consider a fixed integer kk. Then, the graph GkG_k is an undirected graph with nn vertices, where an edge between vertices uu and vv exists if and only if the distance between vertices uu and vv in the given tree is at least kk.

For each kk from 11 to nn, print the number of connected components in the graph GkG_k.

给你一棵树(一个无环的连通图),该树包含 nn 个顶点。

考虑一个固定的整数 kk。定义图 GkG_k 为一个具有 nn 个顶点的无向图,其中顶点 uu 与 vv 之间存在一条边,当且仅当 uu 与 vv 在给定树中的距离至少为 kk。

对每个从 11 到 nn 的 kk,输出图 GkG_k 中连通分量的个数。

输入格式

The first line contains the integer nn (2≤n≤1052 \le n \le 10^5) — the number of vertices in the graph.

Each of the next n−1n-1 lines contains two integers uu and vv (1≤u,v≤n1 \le u, v \le n), denoting an edge between vertices uu and vv in the tree. It is guaranteed that these edges form a valid tree.

第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5)—— 图中顶点的数量。

接下来的 n−1n-1 行,每行包含两个整数 uu 和 vv(1≤u,v≤n1 \le u, v \le n),表示树中顶点 uu 与顶点 vv 之间的一条边。保证这些边构成一棵合法的树。

输出格式

Output nn integers: the number of connected components in the graph GkG_k for each kk from 11 to nn.

输出 nn 个整数:对每个从 11 到 nn 的 kk,图 GkG_k 中连通分量的个数。

输入输出样例

  • 输入#1

    6
    1 2
    1 3
    2 4
    2 5
    3 6

    输出#1

    1 1 2 4 6 6
  • 输入#2

    5
    1 2
    2 3
    3 4
    3 5

    输出#2

    1 1 3 5 5

说明/提示

In the first example: If k=1k=1, the graph has an edge between each pair of vertices, so it has one component. If k=4k=4, the graph has only edges 4↔64 \leftrightarrow 6 and 5↔65 \leftrightarrow 6, so the graph has 44 components.

In the second example: when k=1k=1 or k=2k=2 the graph has one component. When k=3k=3 the graph GkG_k splits into 33 components: one component has vertices 11, 44 and 55, and two more components contain one vertex each. When k=4k=4 or k=5k=5 each vertex is a separate component.

在第一个例子中:若 k=1k=1,则图中每对顶点之间都有一条边,因此该图只有一个连通分量;若 k=4k=4,则图中仅有边 4↔64 \leftrightarrow 6 和 5↔65 \leftrightarrow 6,因此该图有 44 个连通分量。

在第二个例子中:当 k=1k=1 或 k=2k=2 时,图只有一个连通分量;当 k=3k=3 时,图 GkG_k 分裂为 33 个连通分量:其中一个连通分量包含顶点 11、44 和 55,另外两个连通分量各自仅含一个顶点;当 k=4k=4 或 k=5k=5 时,每个顶点各自构成一个连通分量。

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

首页