Under construction

Still being built. Things may change

Removing Vertices

Time limit2sMemory limit1024 MB

Summary
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 (n+1)(n + 1) vertices numbered from 00 to nn. The graph has no loops and no multiple edges. Every cycle passes through vertex 00. Remove the minimum possible number of vertices so that the graph has no cycles. Vertex 00 cannot be removed.

Input

The first line contains two integers nn and mm: the number of vertices excluding vertex 00 and the number of edges (1≤n≤1051 \le n \le 10^5, 1≤m≤1061 \le m \le 10^6). Each of the next mm lines contains two integers aa and bb, the endpoints of an edge (0≤a,b≤n0 \le a, b \le n). It is guaranteed that every cycle passes through vertex 00.

Output

On the first line, print one integer kk, the minimum number of vertices to remove. On the second line, print the kk vertex numbers to remove in any order. If several optimal answers exist, print any one of them.

Examples2

  1. Example 1

    Input
    4 6
    0 1
    1 2
    2 0
    0 3
    3 4
    4 0
    
    Expected output
    2
    1 3
    
  2. Example 2

    Input
    3 5
    0 1
    1 2
    2 0
    2 3
    3 0
    
    Expected output
    1
    2