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: Runtime Error)

class Node
  attr_accessor :pre, :parent, :child, :lowest, :visited
  def initialize
    @pre = -1
    @parent = -1
    @child = []
    @lowest = -1
    @visited = false
  end
end

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

  g[c].child.size.times{|i|
    j = g[c].child[i]
    if g[j].visited == false
      g[j].parent = c
      dfs(j, c, t, 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

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

t = 1
dfs(0, -1, t, graph)

ap = []
np = 0
v.times{|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
}