QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 70

#2535. 蓝细菌

Statistiques

年轻的微生物学家 Maja 正在用一种名为 Stigonema arboreus 的蓝细菌制作微型圣诞树。这种蓝细菌以其由单个细胞组成的菌落而闻名,这些细胞相互连接,形成树状图。更准确地说,对于菌落中的每一对蓝细菌,从一个蓝细菌到另一个蓝细菌都存在一条唯一的路径。

Maja 希望她的圣诞树菌落包含一条尽可能长的蓝细菌链。链由一系列蓝细菌确定,其中每个蓝细菌最多出现一次,且每对相邻的蓝细菌都直接相连。由于她目前拥有的菌落都不够长,Maja 将不得不把一些菌落连接在一起。她通过反复选择来自不同菌落的两个蓝细菌,将它们靠近,并用强力胶将它们连接起来。由于细菌对环很敏感,Maja 必须小心,不能在任何时候连接来自同一个菌落的两个细菌。通过一系列这样的粘合过程,Maja 希望获得一个包含最长可能链的菌落。

Maja 厌倦了使用显微镜,而且蓝细菌非常多。请帮助 Maja 确定通过连接菌落所能获得的最长蓝细菌链的长度。链的长度由构成它的蓝细菌数量决定。

输入格式

第一行包含正整数 $n$ 和 $m$ ($1 \le n \le 100\,000$, $0 \le m < n$),分别表示蓝细菌的数量和它们之间的直接连接数。

接下来的 $m$ 行包含一对正整数 $a_i, b_i$ ($1 \le a_i, b_i \le n$),表示细菌 $a_i$ 和 $b_i$ 直接相连。没有细菌直接与自身相连,且不会列出重复的连接。

这些连接使得细菌形成了一些菌落,每个菌落都是一棵树。

输出格式

在唯一的一行中打印最终菌落中可能的最长链长度。

子任务

子任务 分值 数据范围
1 15 $m = n - 1$
2 6 $b_i = a_i + 1$ 对于每个 $i = 1, \dots, m$
3 6 $1 \le a_i \le 2$ 对于每个 $i = 1, \dots, m$
4 15 $1 \le n \le 1000$
5 28 无附加限制

样例

输入 1

100 0

输出 1

100

输入 2

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

输出 2

6

输入 3

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

输出 3

5

说明

第二个样例的说明: 在第二个样例中,有两个蓝细菌菌落。在第一个菌落中,所有蓝细菌都直接连接到蓝细菌 1,在第二个菌落中,所有蓝细菌都直接连接到蓝细菌 5。如果连接除 1 和 5 之外的任意两个蓝细菌,所得菌落将包含最长的可能链。例如,如果连接 2 和 6,其中一条链可以是 3 - 1 - 2 - 6 - 5 - 7,其长度为 6。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.