P14613 [CodeChef] FAILURE
提高+
题目描述

Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef has always dreamed of becoming an employee of the "Hack and Manipulate Group". Their work is simple ― attacking networks. They gave Chef the following task to assess his programming skills, but Chef is too busy cooking "Vegetable Gourmet". Can you solve the task for him?

A network consists of $N$ nodes (numbered $1$ through $N$) and $M$ bidirectional connections between pairs of these nodes. A robust network is a network that contains a cycle. Shutting down a node means removing that node (and all direct connections it is part of) from the network.

You may shut down at most one node. If the network was robust before it was shut down and is not robust afterwards, this node is called the point of failure.

Is the initial network robust? If it is robust, does it have a point of failure? If it does, find the point of failure with the smallest number.

------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $M$.
Each of the following $M$ lines contains two space-separated integers $u$ and $v$ denoting that nodes $u$ and $v$ are directly connected.

------ Output ------
For each test case, print a single line containing one integer ― the smallest number of a point of failure, or $-1$ if the network does not have a point of failure.

------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 10^{5}$
$0 ≤ M ≤ 10^{5}$
$1 ≤ u, v ≤ N$

------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 100$
$N - 1 ≤ M ≤ N + 1$
the given graph is connected

Subtask #2 (10 points): $1 ≤ N ≤ 100$

Subtask #3 (30 points): $1 ≤ N ≤ 1,000$

Subtask #4 (50 points): original constraints

----- Sample Input 1 ------
5

5 5

5 1

5 2

1 2

2 3

2 4

5 6

4 5

4 1

4 2

4 3

5 1

5 2

5 5

3 4

3 5

3 1

3 2

4 2

4 1

3 4

6 6

1 2

2 3

3 1

4 5

5 6

6 4
----- Sample Output 1 ------
1

4

2

-1

-1

输入格式

见题面

输出格式

见题面

样例输入
5 5 5 5 1 5 2 1 2 2 3 2 4 5 6 4 5 4 1 4 2 4 3 5 1 5 2 5 5 3 4 3 5 3 1 3 2 4 2 4 1 3 4 6 6 1 2 2 3 3 1 4 5 5 6 6 4
样例输出
1 4 2 -1 -1