Problem:
Articulation Points

Find articulation points of a given undirected graph G(V, E).

A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph.

Input

|V| |E|
s0 t0
s1 t1
:
s|E|-1 t|E|-1

, where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.

si and ti represent source and target verticess of i-th edge (undirected).

Output

A list of articulation points of the graph G ordered by name.

Constraints

1 ≤ |V| ≤ 100,000

0 ≤ |E| ≤ 100,000

The graph is connected

There are no parallel edges

There are no self-loops

Sample Input 1

4 4
0 1
0 2
1 2
2 3

Sample Output 1

2

Sample Input 2

5 4
0 1
1 2
2 3
3 4

Sample Output 2

1
2
3

Solution in Ruby (judge verdict: Accepted)

module SimpleUndirectedGraphic
    require 'set'

    def each_connected_component(&block)
        return enum_for(__method__) unless block_given?
        reached = Set.new
        each_node do |s|
            next if reached.include?(s)
            cc = Set[s]
            queue = [s]
            until queue.empty?
                u = queue.shift
                each_neighbour(u) do |v|
                    next if cc.include?(v)
                    cc << v
                    queue << v
                end
            end
            block.call(cc)
            reached += cc
        end
    end

    def connected_components
        each_connected_component.to_a
    end

    def dfs(root, callback = Hash.new())
        known = Set[
            :WHEN_VISIT,
            :WHEN_CHECK,
            :WHEN_MOVE,
            :WHEN_RETURN,
            :WHEN_LEAVE,
        ]
        callback.keys.each do |name|
            raise "unknown callback: #{name}" if ! known.include?(name)
        end

        f = nil
        f.call(root) if f = callback[:WHEN_VISIT]
        stack = [[root, to_enum(:each_neighbour, root)]]
        parent = { root => root }
        until stack.empty?
            u, itr = stack[-1]
            begin
                v = itr.next
                f.call(u, v) if f = callback[:WHEN_CHECK]
                next if v == parent[u]|| parent[v]

                stack << [v, to_enum(:each_neighbour, v)]
                parent[v] = u
                f.call(u, v) if f = callback[:WHEN_MOVE]

                f.call(v) if f = callback[:WHEN_VISIT]
            rescue StopIteration
                stack.pop
                f.call(u) if f = callback[:WHEN_LEAVE]
                if ! stack.empty?
                    f.call(stack[-1][0], u) if f = callback[:WHEN_RETURN]
                end
            end
        end
    end

    def each_biconnected_component(root = each_node.to_a[0])
        return to_enum(__method__) unless block_given?

        visit_order = {}
        backtrack = {}
        parent = {}
        edge_stack = []

        callback = {
            :WHEN_VISIT => -> u {
                backtrack[u] = visit_order[u] = visit_order.size
            },
            :WHEN_CHECK => -> u, v {
                if v != parent[u] && o = visit_order[v]
                    backtrack[u] = o if o < backtrack[u]
                end
            },
            :WHEN_MOVE => -> u, v {
                edge_stack << [u, v]
                parent[v] = u
            },
            :WHEN_RETURN => -> u, v {
                l = backtrack[v]
                if visit_order[u] <= l
                    bcc = Set[u]
                    loop do
                       x, y = edge_stack.pop
                       bcc << y
                       break if x == u
                    end
                    yield(bcc)
                end
                backtrack[u] = l if l < backtrack[u]
            },
        }

        dfs(root, callback)
    end

    def biconnected_components
        each_biconnected_component.to_a
    end

    def cut_points
        appearance = Hash.new(0)
        each_biconnected_component do |s|
            s.each {|u| appearance[u] += 1}
        end
        Set[*appearance.keys.select{|u| appearance[u] > 1}]
    end
end

class Hash
    include SimpleUndirectedGraphic
    alias each_node each_key
    def each_neighbour(u)
        self[u].each do |v|
            yield(v)
        end
    end
end

n, m = gets.split.map(&:to_i)
g = {}
(0..n-1).each {|u| g[u] = Set.new }

m.times do
    u, v = gets.split.map(&:to_i)
    g[u] << v
    g[v] << u
end

#p g.biconnected_components

puts g.cut_points.sort