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)

MAX = 100001
class Node
  attr_accessor :pre, :parent, :child, :lowest, :visited
  def initialize
    @pre = MAX
    @parent = 0
    @child = []
    @lowest = MAX
    @visited = false
  end
end

# def dfs(c, p, g)
#   g[c].pre = g[c].lowest = $t
#   $t += 1
#   g[c].visited = true

#   g[c].child.each{|j|
#     if g[j].visited == false
#       g[j].parent = c
#       dfs(j, c, g)
#       g[c].lowest = g[j].lowest if g[j].lowest < g[c].lowest
#     elsif j != p
#       g[c].lowest = g[j].pre if g[j].pre < g[c].lowest
#     end
#   }
# end

def dfs(c, p, g)
  stack = []
  g[c].pre = g[c].lowest = $t
  g[c].visited = true
  stack << c

  while stack.size > 0
    n = stack[-1]
    j = -1
    g[n].child.each{|i|
      if g[i].visited == false
        j = i
        $t += 1
        g[i].pre = g[i].lowest = $t
        g[i].parent = n
        g[i].visited = true
        g[n].lowest = g[i].lowest if g[i].lowest < g[n].lowest
        stack << j
        break
      elsif i != g[n].parent
        g[n].lowest = g[i].pre if g[i].pre < g[n].lowest
      end
    }
    if j == -1
      stack.pop
      g[n].child.each{|i|
        next if i == stack[-1]
        g[n].lowest = g[i].lowest if g[i].lowest < g[n].lowest
      }
    end
  end
end

$t = 1
v, e = gets.split.map(&:to_i)
graph = Array.new(v){Node.new}
e.times{
  s, t = gets.split.map(&:to_i)
  graph[s].child << t
  graph[t].child << s
}

dfs(0, -1, graph)

ap = []
np = 0
1.upto(v-1){|i|
  p = graph[i].parent
  if p == 0
    np += 1
  elsif graph[p].pre <= graph[i].lowest
    ap << p
  end
}
ap << 0 if np > 1
ap.uniq.sort.each{|i|
  puts i
}