#P11954. Edge Removal to Disconnect Graph
Edge Removal to Disconnect Graph
Edge Removal to Disconnect Graph
Given a simple undirected connected graph with \(n\) vertices (numbered from 1) and \(m\) edges, you are allowed to remove an arbitrary set of edges so that:
- The resulting graph is disconnected.
- The resulting graph does not contain any isolated vertex (i.e. every vertex has degree at least 1).
Construct such an edge removal scheme or report \(-1\) if it is impossible. If there are multiple valid schemes, output any one of them.
Note: You do not need to minimize the number of removed edges.
inputFormat
The first line contains two integers \(n\) and \(m\) (with \(2 \le n \le 10^5\) and \(n-1 \le m \le 10^5\)), denoting the number of vertices and edges respectively.
Each of the following \(m\) lines contains two integers \(u\) and \(v\) (\(1 \le u, v \le n\) and \(u \neq v\)), representing an edge between vertices \(u\) and \(v\). It is guaranteed that the graph is simple and connected.
outputFormat
If a valid edge removal scheme exists, first output an integer \(k\) representing the number of edges to remove, followed by a line with \(k\) space-separated integers denoting the indices of the edges to be removed (edges are numbered in the order of input, starting from 1). If no valid scheme exists, output \(-1\).
sample
4 4
1 2
2 3
3 4
1 4
2
2 4
</p>