当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7251:Minimum Diameter

题目描述
The following is the **minimum diameter problem**.

- You are given a forest (an acyclic undirected graph) with $n$ vertices. Consider adding some edges to the forest to turn it into a tree. Find the minimum possible diameter of the resulting tree.

Here the diameter of a tree is defined as the maximum distance among all pairs of vertices. The distance of two vertices in a tree is defined as the number of edges on the shortest path between them.

You are given a forest of $n$ vertices and $m$ edges. The edges are numbered from $1,2,...,m$. For each $i=1,2,...,m$, consider the forest only containing the first $i$ edges, and compute the answer to the **minimum diameter problem** on this forest.
输入解释
The first line contains a single integer $T$ $(1\le T\le 10^3)$ - the number of test cases.

For each test case, the first line contains two integers $n,m$ $(2\le n\le 10^5,1\le m< n)$.

Each of next $m$ lines contains two integers $u$ and $w$ $(1\le u,w\le n)$ - describes the $i$-th edge of the forest.

It's guarantee that the sum of $n$ among all test cases is not greater than $10^6$ and $m$ edges form a forest.
输出解释
For each test case, output $m$ lines. The $i$-th of these lines should contain a single integer, indicating the answer to the **minimum diameter problem** on the forest only containing the first $i$ edges of the original forest.
输入样例
1
5 4
1 2
2 3
3 4
4 5
输出样例
2
2
3
4

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7251

最后修改于 2022-09-15T06:17:37+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 524288/524288K(Java/Others)