Public Judge

pjudge

実行時間制限: 2 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓
統計

Given a connected simple undirected graph with $n$ vertices and $m$ edges, where the $i$-th edge ($1 \le i \le m$) connects vertices $u_i$ and $v_i$ ($1 \le u_i, v_i \le n$).

Initially, all vertices are white. Two players, Alice and Bob, play a game on this graph with the following rules:

  • Initially, Alice chooses a vertex $x$ ($1 \le x \le n$) and colors it black.
  • Subsequently, Bob performs several rounds of operations:
    • In each round, Bob can choose one vertex or two vertices, provided that all chosen vertices are currently white and each chosen vertex has at least one neighbor that is already black.
    • Bob colors the chosen vertices black.
  • The game ends when all vertices are colored black. The time consumed by Bob is the number of rounds he performs.

Bob wants the game to end as quickly as possible, while Alice wants the game to end as slowly as possible. Assuming both players play optimally, determine the number of rounds after which the game will end.

Input

Each test case may contain multiple test sets.

The first line of the input contains an integer $T$, representing the number of test cases.

For each test case:

The first line contains two integers $n$ and $m$, describing the number of vertices and edges in the graph.

The next $m$ lines each contain two integers $u, v$, describing an edge.

It is guaranteed that there are no multiple edges or self-loops, and the graph is a connected undirected graph.

Output

For each test case, output a single integer representing the answer.

Examples

Input 1

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

Output 1

3
2
2

Note

For the first test case, one optimal strategy for Alice is to choose vertex $1$ and color it black. Then:

  • In the first round, Bob chooses vertex $2$ and colors it black.
  • In the second round, Bob chooses vertex $3$ and colors it black.
  • In the third round, Bob chooses vertex $4$ and colors it black.

A total of $3$ rounds are required.

For the second test case, one optimal strategy for Alice is to choose vertex $1$ and color it black. Then:

  • In the first round, Bob chooses vertices $2, 3$ and colors them black.
  • In the second round, Bob chooses vertex $4$ and colors it black.

A total of $2$ rounds are required.

For the third test case, one optimal strategy for Alice is to choose vertex $1$ and color it black. Then:

  • In the first round, Bob chooses vertices $2, 3$ and colors them black.
  • In the second round, Bob chooses vertices $4, 5$ and colors them black.

A total of $2$ rounds are required.

Subtasks

For all data, $2 \le n \le 3 \times 10^5$, $n-1 \le m \le 3 \times 10^5$, $1 \le u_i, v_i \le n$.

For all data, $\sum n \le 3 \times 10^5$, $\sum m \le 3 \times 10^5$.

It is guaranteed that the input graph is a simple connected undirected graph.

Subtask ID $\sum n \le$ $\sum m \le$ Special Property Score
$1$ $16$ $40$ None $6$
$2$ $1\,000$ $2\,000$ $10$
$3$ $10^5$ $10^5$ $m=n-1$ $18$
$4$ $m = n$ $13$
$5$ $3 \times 10^5$ $3\times 10^5$ Diameter of the graph is $1$ to $n$ $21$
$6$ None $32$

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.