Kid's Nightmare
Time limit3sMemory limit1024 MB
Remove vertices so the remaining graph has no cycles while keeping as many as possible, in a connected graph where every cycle of length four or more has a chord.
- Level
Medium7 of 10
- Topics
- Graph, Greedy, Implementation
- Solved
- No attempts yet
Problem
Vasya likes trees and hates cycles in graphs very much. Whenever he faces a cactus problem at a contest, he gets upset and starts a discussion on a well-known forum in the community.
Today is the night before an important contest at a training camp, and Vasya has a nightmare. In it, he sees a connected undirected graph full of cycles: cycles with cycles inside them, and more cycles inside those. The graph is so terrible that for every simple cycle with at least four vertices, there is an edge connecting two non-adjacent vertices of that cycle.
The only thing Vasya can do is delete a vertex together with all edges incident to it. Help him delete some vertices so that the number of remaining vertices is as large as possible and the remaining graph has no cycles at all. The graph may become disconnected after the deletions.
Input
The first line contains two integers and , the number of vertices and edges in the graph (). Each of the next lines contains a pair of integers and , the vertices connected by an edge (). It is guaranteed that the graph is connected, has no loops or multiple edges, and that for every simple cycle with at least four vertices, there is an edge connecting two non-adjacent vertices of the cycle.
Output
On the first line, print one integer , the maximum number of vertices that can remain in the graph. On the second line, print integers, the numbers of the vertices that remain. If there are several solutions, any of them is accepted.
Hint
In the picture below, you can see the graph from sample test 3. Solid vertices and edges are the ones present in the resulting graph, and dashed vertices and edges are the deleted ones.
