Advanced Graphs Special edges and paths
490. Articulation points
You are given an undirected graph with n vertices, numbered from 0 to n - 1. Each pair [u, v] in
edges is an edge between vertices u and v.
A vertex is an articulation point if removing it, together with its edges, splits the piece of the graph it belongs to into two or more pieces. The graph itself can already be in several pieces, with no edges between them.
Return every articulation point in increasing order, each one once. If the graph has none, return [-1].
Example 1
Input: n = 7
edges = [[0, 1],
[1, 2],
[2, 0],
[1, 3],
[3, 4],
[4, 5],
[5, 3],
[5, 6]]
[1,3,5]Explanation: Removing 1 cuts 0 and 2 off from the rest. Removing 3 leaves 0, 1, 2 in one piece and 4, 5, 6 in another. Removing 5 leaves 6 alone. Every other vertex can go, and what remains of the graph stays joined.
Example 2
Input: n = 4, edges = [[0, 1], [1, 2], [2, 3], [3, 0]]
[-1]Explanation: The four vertices form a ring. Removing any one of them leaves a path through the other three, so there is no articulation point.
Example 3
Input: n = 6, edges = [[4, 2], [2, 5], [0, 1]]
[2]Explanation: The graph is in three pieces, and vertex 3 has no edges at all. Removing 2 splits its piece into 4 and 5. Removing 0, 1, 4 or 5 leaves a single vertex behind, which is still one piece.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ n ≤ 1050 ≤ edges.length ≤ 105edges[i].length == 20 ≤ ui, vi < nui ≠ vi- No edge appears twice:
[u, v]and[v, u]are the same edge.
Clarifying questions
What you would ask an interviewer before writing any code.