Critical Junctions
A road map has n junctions numbered 0 to n - 1. roads is a list of pairs [a, b] with a != b, each a two-way road between junctions a and b; the same pair may appear more than once.
A junction is critical when closing it, together with all the roads that touch it, splits the map: afterwards some two other junctions that used to have a route between them have none. Return how many junctions are critical. Return 0 when there is none.
Example 1
Closing 2 separates the triangle from 3 and 4; closing 3 strands 4. Closing any other junction splits nothing.
Example 2
Close any junction of a triangle and the other two still have their road.
Constraints
1 <= n <= 500 <= len(roads) <= 1000 <= a, b <= n - 1anda != b
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.