Problem 273
Count Articulation Points
Hard · 30 pts · Graph, Depth-First Search, Biconnected Component
Problem
In an undirected graph, an articulation point (cut vertex) is a node whose removal, together with its edges, increases the number of connected components among the remaining nodes. Count the articulation points of the given graph. Use one DFS with discovery times and low values, as for bridges. A non-root node u is an articulation point if it has a child v with low[v] >= disc[u]. The root of a DFS tree is an articulation point exactly when it has two or more children in that tree.
Input
First line: integers N (nodes, labelled 1..N) and M (edges). Next M lines: an edge u v.
Output
Print the number of articulation points.
Constraints
1 <= N <= 100000; 0 <= M <= 200000; no self-loops or repeated edges
Example input
5 5 1 2 2 3 3 1 3 4 4 5
Example output
2
Explanation
Removing node 3 separates the pair {1, 2} from {4, 5}, and removing node 4 cuts off node 5. Removing 1, 2 or 5 leaves everything else connected. So there are 2 articulation points.