CF1338D.Nested Rubber Bands

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have a tree of nn vertices. You are going to convert this tree into nn rubber bands on infinitely large plane. Conversion rule follows:

  • For every pair of vertices aa and bb, rubber bands aa and bb should intersect if and only if there is an edge exists between aa and bb in the tree.
  • Shape of rubber bands must be a simple loop. In other words, rubber band is a loop which doesn't self-intersect.

Now let's define following things:

  • Rubber band aa includes rubber band bb, if and only if rubber band bb is in rubber band aa's area, and they don't intersect each other.
  • Sequence of rubber bands a1,a2,…,aka_{1}, a_{2}, \ldots, a_{k} (k≥2k \ge 2) are nested, if and only if for all ii (2≤i≤k2 \le i \le k), ai−1a_{i-1} includes aia_{i}.

This is an example of conversion. Note that rubber bands 55 and 66 are nested.

It can be proved that is it possible to make a conversion and sequence of nested rubber bands under given constraints.

What is the maximum length of sequence of nested rubber bands can be obtained from given tree? Find and print it.

你有一棵包含 nn 个顶点的树。你需要将这棵树转化为平面上(平面无限大)的 nn 个橡皮筋。转化规则如下:

  • 对于任意一对顶点 aa 和 bb,橡皮筋 aa 与橡皮筋 bb 必须相交 当且仅当 树中存在连接 aa 和 bb 的一条边。
  • 橡皮筋的形状必须是一个简单闭合曲线(即不自交的环)。

现在我们定义如下概念:

  • 橡皮筋 aa 包含 橡皮筋 bb,当且仅当橡皮筋 bb 完全位于橡皮筋 aa 所围成的区域内,且二者互不相交。
  • 橡皮筋序列 a1,a2,…,aka_{1}, a_{2}, \ldots, a_{k}(其中 k≥2k \ge 2)称为嵌套的,当且仅当对所有 ii(2≤i≤k2 \le i \le k),均有 ai−1a_{i-1} 包含 aia_{i}。

这是一个合法的转化示例。注意:橡皮筋 55 和 66 是嵌套的。

可以证明,在给定约束下,总存在一种满足条件的转化方式,并可构造出嵌套的橡皮筋序列。

问:对于给定的树,所能得到的嵌套橡皮筋序列的最大长度是多少?请计算并输出该最大长度。

输入格式

The first line contains integer nn (3≤n≤1053 \le n \le 10^{5}) — the number of vertices in tree.

The ii-th of the next n−1n-1 lines contains two integers aia_{i} and bib_{i} (1≤ai<bi≤n1 \le a_{i} \lt b_{i} \le n) — it means there is an edge between aia_{i} and bib_{i}. It is guaranteed that given graph forms tree of nn vertices.

第一行包含一个整数 nn(3≤n≤1053 \le n \le 10^{5})—— 表示树中顶点的数量。

接下来的 n−1n-1 行中,第 ii 行包含两个整数 aia_{i} 和 bib_{i}(1≤ai<bi≤n1 \le a_{i} \lt b_{i} \le n)—— 表示顶点 aia_{i} 与 bib_{i} 之间存在一条边。保证所给图构成一棵含有 nn 个顶点的树。

输出格式

Print the answer.

输出答案。

输入输出样例

  • 输入#1

    6
    1 3
    2 3
    3 4
    4 5
    4 6

    输出#1

    4
  • 输入#2

    4
    1 2
    2 3
    3 4

    输出#2

    2

说明/提示

In the first sample, you can obtain a nested sequence of 44 rubber bands(11, 22, 55, and 66) by the conversion shown below. Of course, there are other conversions exist to make a nested sequence of 44 rubber bands. However, you cannot make sequence of 55 or more nested rubber bands with given tree.

You can see one of the possible conversions for the second sample below.

在第一个样例中,你可以通过如下所示的变换,得到一个包含 44 个橡皮筋(编号为 11、22、55 和 66)的嵌套序列。当然,还存在其他变换方式,也能得到长度为 44 的嵌套橡皮筋序列。然而,在给定的树结构下,你无法构造出长度为 55 或更长的嵌套橡皮筋序列。

你可以看到第二个样例的一种可能变换方式如下所示。

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

首页