Count Articulation Points in an Undirected Graph

Given an undirected graph, count how many articulation points it contains. An articulation point is a vertex whose removal disconnects the graph. Pattern focus: Articulation Points. This is the counting version of cut-vertex detection.

Input Format

n = number of vertices, edges = undirected edges [u, v]

Output Format

number of articulation points

Constraints

  • 1 <= n <= 10^5
  • 1 <= edges.length <= 2 * 10^5

Examples

Example 1:

Input:

n = 5
edges = [[1,2],[2,3],[3,1],[3,4],[4,5]]

Output:

2

Explanation:

Vertices 3 and 4 are articulation points.

Example 2:

Input:

n = 4
edges = [[1,2],[1,3],[1,4]]

Output:

1

Explanation:

Only the center vertex is a cut vertex.

Example 3:

Input:

n = 3
edges = [[1,2],[2,3],[3,1]]

Output:

0

Explanation:

A cycle has no articulation points.

Loading...
Count Articulation Points in an Undirected Graph