Removing Vertices
Time limit2sMemory limit1024 MB
Given a graph where every cycle passes through vertex 0, remove the fewest vertices other than 0 so no cycles remain, and print which ones.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Tree, DFS, Graph
- Solved
- No attempts yet
Problem
You are given an undirected graph with vertices numbered from to . The graph has no loops and no multiple edges. Every cycle passes through vertex . Remove the minimum possible number of vertices so that the graph has no cycles. Vertex cannot be removed.
Input
The first line contains two integers and : the number of vertices excluding vertex and the number of edges (, ). Each of the next lines contains two integers and , the endpoints of an edge (). It is guaranteed that every cycle passes through vertex .
Output
On the first line, print one integer , the minimum number of vertices to remove. On the second line, print the vertex numbers to remove in any order. If several optimal answers exist, print any one of them.