Graph bridges
InterviewTime limit1sMemory limit256 MB
Find every bridge in a connected undirected graph and print them sorted by endpoint.
Problem
Given a graph, find every bridge and print them.
A bridge is an edge whose removal splits the graph into two or more parts. In other words, removing it increases the number of connected components.
Input
The first line has the number of vertices and the number of edges . (, )
Each of the next lines has two integers and , meaning that vertex and vertex are joined. Every edge is undirected.
The graph is always connected, no edge is given more than once, and and are never equal. Vertices are numbered from to .
Output
Print the number of bridges on the first line.
On each of the next lines print one bridge in the form A B with . Order the bridges by in increasing order, and by when ties. Print each edge only once. If is 0, print only the first line.