Zoj2588 undirected graph side-cutting Tarjan Algorithm

Source: Internet
Author: User

Burning bridges

Time limit:
5 seconds memory limit:

32768 KB

Ferry
Kingdom
Is a nice little country located on N islands that are
Connected by M bridges. All bridges are very beautiful and are loved
Everyone in the Kingdom. Of course, the system of bridges is designed in such
Way that one can get from any island to any other one.

But recently the great sorrow has come to the Kingdom. Ferry kingdom
Was conquered by the armies of the great warrior Jordan and he has decided
Burn all the bridges that connected the islands. This was a very cruel
Deploy, but the Wizards of Jordan
Have advised him no to do so, because after that his own armies wocould not be
Able to get from one island to another. So Jordan decided to burn as login
Bridges as possible so that is was still possible for his armies to get from
Any island to any other one.

Now the poor people of ferry
Kingdom wonder what
Bridges will be burned. Of course, they cannot learn that, because the list
Bridges to be burned is kept in great secret. However, one old man said that
You can help them to find the set of bridges that certainly will not be burned.

So they came to you and asked for help. Can you do that?

Input

The input contains multiple test cases. The first line of the input is a single
Integer T (1 <= T <= 20) which is the number of test cases. t test cases
Follow, each preceded by a single blank line.

The first line of each case contains N and M-the number of islands and
Bridges in ferry Kingdom respectively (2 <= n <= 10
000, 1 <= m <= 100 000). Next m lines contain two different integer
Numbers each and describe bridges. Note that there can be several bridges
Between a pair of islands.

Output

On the first line of each case print K-the number of bridges that will
Certainly not be burned. On the second line print K integers-the numbers
These bridges. bridges are numbered starting from one, as they are given in
Input.

Two consecutive cases shocould be separated by a single blank line. No blank
Line shoshould be produced after the last test case.

Sample Input

2

6 7

1 2

2 3

2 4

5 4

1 3

4 5

3 6

10 16

2 6

3 7

6 5

5 9

5 4

1 2

9 8

6 4

2 10

3 8

7 9

1 4

2 4

10 5

1 6

6 10

Sample output

2

3 7

1

4

Evaluate all cut edges of an undirected graph
,
Used
Tarjan
Algorithm
,
Due to memory restrictions
,
The adjacent matrix cannot be used.
,
Only an adjacent table can be used.
.

The Code is as follows:
:

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.