8666: Minimum Diameter

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

The following is the minimum diameter problem.

  • You are given a forest (an acyclic undirected graph) with nn 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 mm edges. The edges are numbered from ,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(1T103) - the number of test cases.

For each test case, the first line contains two integers n,m(2n105,1m<n).

Each of next mm lines contains two integers u and w (1u,wn) - describes the i-th edge of the forest.

It's guarantee that the sum of n among all test cases is not greater than 106 and m edges form a forest.

输出格式

For each test case, output mm 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