#K1681. Maze Diameter

    ID: 24569 Type: Default 1000ms 256MiB

Maze Diameter

Maze Diameter

You are given a maze represented as an undirected graph. The maze consists of N rooms and E corridors connecting pairs of rooms. Your task is to compute the diameter of the maze. The diameter is defined as:\ (\displaystyle d_{maze} = \max_{u,v \in V} d(u,v))\ where (d(u,v)) is the shortest path distance between rooms u and v in the same connected component. For disconnected graphs, consider the diameter of each connected component and output the maximum value among them.

For each test case, the first line contains two integers N and E, representing the number of rooms and corridors respectively. The next E lines each contain two integers u and v indicating that there is an undirected corridor between room u and room v.

Your program should use standard input and output.

inputFormat

Standard input contains multiple test cases. The first line contains an integer T (T ≥ 1), denoting the number of test cases. For each test case:

The first line contains two integers N and E, representing the number of rooms and corridors respectively. Each of the next E lines contains two integers u and v describing a corridor connecting room u and room v.

outputFormat

For each test case, output a single line containing the diameter of the maze (i.e., the maximum shortest path distance within a connected component).## sample

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

2

</p>