F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Minimum Diameter

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 235    Accepted Submission(s): 61


Problem Description
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.
 

Input
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.
 

Output
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.
 

Sample Input
1 5 4 1 2 2 3 3 4 4 5
 

Sample Output
2 2 3 4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.001000(s) query 1, Server time : 2025-04-01 06:49:18, Gzip enabled